Powershell scriipt for mirror user accounts group membership

 

I have created small power shell script where we can use this for mirror active directory user group membership. This script is usefulll when the new user coming to the organization we should give the correct group membership.

 

 

 

$strsourceuser
$struser
Write-Host “Please enter the user name of the source user”
$strsourceuser=read-host

Write-Host “Please type the user name which you want to mirror”

$struser=Read-Host

$strgmem=Get-ADPrincipalGroupMembership $strsourceuser

for($a=0; $a -le (($strgmem).Count)-1;$a++)
{

Write-Host $strgmem[$a].name
$grpname=$strgmem[$a].name

Add-ADGroupMember $grpname -Members $struser -ErrorAction SilentlyContinue

}