#PS Script that filters AD Computers and moves it to specified OU

I wrote this script to filter my Active Directory Domain for Computers beginning with “SMB-” and move them to an Organizational Unit (OU) with the name “SMB-OU”.

You can use the script but you have to change the OU, Computer filter and Domain so that it matches your search and domain criteria.

I use the Outfile command to create a logfile from the movement for documentation.

Get-ADComputer -Filter * -Properties name | #get all active directory computers
where { $_.Name -match ‘SMB-*’} | #with computername that includes “SMB-“
Out-File c:\move_resultates_before.txt #writes status before any computer will moved in output file
Get-ADComputer -Filter * -Properties name | #get all active directory computers
where { $_.Name -match ‘SMB-*’} | #with computername that includes “SMB-“
Move-ADObject -TargetPath “OU=SMB-OU, DC=Datacenter-Flo, DC=de” #and moves the computer to OU named SMB-OU in domain Datacenter-Flo.de (you have to change to your domain)
Get-ADComputer -Filter * -Properties name | #get all active directory computers
where { $_.Name -match ‘SMB-*’} | #with computername that includes “SMB-“
Out-File c:\move_resultates_aftwe.txt #writes status after the computers were moved in output file
 

At the moment there is no security and other filters included. Only quick and dirty but it’s working.