Quantcast
Channel: Active Directory – Jacques Dalbera's IT world
Viewing all articles
Browse latest Browse all 302

PowerShell – How to add all users in an OU to a Security Group

$
0
0

Import-module ActiveDirectory

$rootOU = “OU=Special Users,OU=Users,DC=MyDomain,DC=com”

$group = “mydomain\group1”

Get-ADUser -SearchBase $rootOu -Filter * | ForEach-Object {Add-ADGroupMember -Identity $group -Members $_ }

You can Schedule this script to run every hour.

 

References:

Get-ADUser http://technet.microsoft.com/en-us/library/ee617241.aspx

Add-ADGroupMember https://technet.microsoft.com/en-gb/library/ee617210.aspx

ForEach-Object https://technet.microsoft.com/en-us/library/hh849731.aspx

PowerShell Variables: http://www.computerperformance.co.uk/powershell/powershell_variables.htm

TechNet Magazine: https://technet.microsoft.com/en-us/magazine/ee677578.aspx



Viewing all articles
Browse latest Browse all 302

Trending Articles