Reputation: 1453
I'm trying to write a script that creates 2 groups and immediatley moves them to an (already existing) OU.
I tried checking possible answers and it shouldn't be too difficult. However, the code that I managed to get along doesn't seem to work:
New-ADGroup -Name "Soccer players" -GroupScope Global
New-ADGroup -Name "Tennis players" -GroupScope Global
Get-ADGroupMember "Soccer players" -Recursive | Move-ADObject –TargetPath "OU=SportGroups,DC=funsports,DC=local"
Get-ADGroupMember "Tennis players" -Recursive | Move-ADObject –TargetPath "OU=SportGroups,DC=funsports,DC=local"
The groups get created but not moved to the OU
I have tried variations of playing with the quotes (at ADGroupMember and target),... But it never seems to work....
Where's my problem?
UPDATE
New-ADGroup -Name "Soccer players" -GroupScope Global –Path "OU=SportGroups,DC=funsports,DC=local"
New-ADGroup -Name "Tennis players" -GroupScope Global –Path "OU=SportGroups,DC=funsports,DC=local"
Creates the groups but not in the SportGroups OU (but in the default 'users' container)
Upvotes: 1
Views: 3997
Reputation: 200233
You may want to move the groups instead of their members:
$ou = 'OU=SportGroups,DC=funsports,DC=local'
Get-ADGroup 'Soccer players' | Move-ADObject –TargetPath $ou
Or you could place the groups in the correct OU upon creation, so you don't need to move them in the first place:
$ou = 'OU=SportGroups,DC=funsports,DC=local'
New-ADGroup -Name 'Soccer players' -Path $ou -GroupScope Global
Upvotes: 3