Quicktip: Moving AD Groups to an OU via Powershell

I hate doing anything manually, so came up with this script that takes an input file and moves all groups referenced in that file to a specific OU:

$Move=import-csv d:\Groups\GroupsToDelete.csv
Import-module ActiveDirectory
foreach ($GGroup in $deletes.cn){
	get-adgroup $GGroup|move-adobject -identity {$_.objectguid} -targetpath 'ou=BLAH,dc=BLEH,dc=com'
}

Script requires the AD Powershell modules to be installed

Advertisements

One thought on “Quicktip: Moving AD Groups to an OU via Powershell

  1. Dan says:

    Great note! Other websites/tutorials show Move-ADObject using the DistringuishedName of the object for the -Identity but that fails with “Move-ADObject : Cross-domain move of non-empty account groups is not allowed”. Using objectguid as in your example works perfectly.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s