Friday, May 13, 2011

PowerShell Scripts Change User Attributes

Just a note on how to search and modify user attributes.  I recently had to use these cmlets to modify the Manager and Company field in AD.  

Modify Attributes for all users risiding in a particular OU. Start listing the OU. In this case all user in PayRoll OU will have Optimus Prime as Manager.

Get-ADUser -Filter * -SearchBase "OU=PayRoll,OU=Accounting,DC=YourDomain,DC=com" | Set-ADUser -Manager "Optimus Prime"

Copying one user’s group memberships to a second user. In this case all group memberships of the user Optimus Prime will get duplicated to MegaTron.

Get-ADPrincipalGroupMembership -Identity OptimusPrime | % {Add-ADPrincipalGroupMembership -Identity MegaTron -MemberOf $_}

Reporting on user accounts with non expiring Passwords.  Format teh output to display any properties.

Search-ADAccount -PasswordNeverExpires | FT Name, ObjectClass, UserPrincipalName

Thanks to the TechRepublic

No comments:

Post a Comment