Quantcast
Channel: Directory Services forum
Viewing all articles
Browse latest Browse all 31638

Power Shell script to get the manager for eah users and put them in a specific group

$
0
0
I created a power shell scrip to get users and for each user get the manager and put him in a specific group but when I am trying to run it I got an error

$username=$Manager|Select-Object*-ExpandPropertyManager is equal null ?

$Users=Get-ADUser-Filter {Enabled-eq$true-andgweVfOpcoId-ne"0" }-SearchScopeSubtree-SearchBase"OU=Opcos,OU=MOSSUsers,OU=MOSS,OU=Sharepoint,DC=sharepdev1,DC=local"

foreach($userin$Users)

{

$Manager=$user|Get-ADUser-Properties*|SelectManager

if($Manager.Manager-ne$null)

{

$username=$Manager|Select-Object*-ExpandPropertyManager

$userstatus=Get-ADUser-Identity$username-PropertiesEnabled

if($userstatus.enabled-eq$ture)

{

$User=Get-ADUser-Identity$username-PropertiesMemberOf

$Group= (Get-ADGroup"Managers").distinguishedName

If ($User.memberOf.Contains($Group))

{

Write-Host"User is already a member of one of the Job Roles"

}

Else

{

Write-Host"User is not a member of any of the Job Roles"

Add-ADGroupMember-IdentityManagers-Member$username

}

}

}

}

 

Import-ModuleActiveDirectory


Viewing all articles
Browse latest Browse all 31638

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>