PSScripts/Add-ADOUToGroup.ps1

12 lines
385 B
PowerShell
Raw Normal View History

2023-12-18 18:00:56 +00:00
# Takes all the users from an OU and adds them to a group.
$OUName = "" # Name of the OU
$GroupName = "" # Name of the Group
$OU = Get-ADOrganizationalUnit -Filter "Name -like '$OUName'" -Properties DistinguishedName
$OUPath = $OU.DistinguishedName
$Users = Get-ADUser -Filter * -SearchBase $OUPath | Select-Object
Add-ADGroupMember -Identity $GroupName -Members $Users