Link to home
Start Free TrialLog in
Avatar of gd6627
gd6627Flag for United States of America

asked on

Powershell to move computers names to a different OU

I have a list of Computer names in a csv file . I need to run this list thru PowerShell so that it can find devices where ever they are  In Ad and then moved them to a specific OU

heres the list of devices

PC03MGQB
PC03MGQU
PC03MGSS
PC03MGSG
PC03MGTA
PC03MGR0
PC03MGTW
PC03MGR4
PC03MGQ9
PC03MGSP


Thank you in advance
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada image

Try the following command...

You need to make sure that you have a heading in the CSV called NAME, with all of the computers beneith.

You will also need to modify the $OU vairable to whatever path you want move the AD computers.
$OU = "ou=destinationOU,dc=domain,dc=com"
$computers = import-csv "c:\filename.csv"
ForEach ($computer in $Computers) {
$Computer.Name
Get-ADComputer -Identity $Computer.Name -Properties Name, DistinguishedName |
Select Name, DistinguishedName |
Export-Csv "c:\ComputerLocations.csv" -nti
$ComputerMove = Import-Csv "c:\ComputerLocations.csv"
ForEach ($Com in $ComputerMove) {
$Comp.DistinguishedName
Move-ADOject -Identity $Comp.DistinguishedName -TargetPath $OU
   }
}

Open in new window


Will.
Avatar of gd6627

ASKER

Cant get it to work ? I have a csv file with computernames and a header as $Computers
ASKER CERTIFIED SOLUTION
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial