Powershell script to move active directory machines to specific ou

powershell

Today I’ll post a simple mini script that moves machines to a specific ou in active directory via powershell

 

The machines will be listed in a txt file like this  ( no spaces only intro )

example (machines.txt)

 

machine1

machine2

machine3

 

Create a ps1 with the following code

get-content machines.txt | % {Get-ADComputer -Identity $_ -server desigual.com} |move-ADObject -TargetPath “Destination OU

 

the destination ou must be in CN format : “OU=EXAMPLE ,OU=COMPUTERS,OU=ES-BARCELONA,OU=ORGANIZATION,DC=COMPANY,DC=com”

 

Enjoy!

 

 

Advertisements

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