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

}

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: