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


Thank you in advance
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Will SzymkowskiSenior Solution ArchitectCommented:
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) {
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) {
Move-ADOject -Identity $Comp.DistinguishedName -TargetPath $OU

Open in new window

gd6627Author Commented:
Cant get it to work ? I have a csv file with computernames and a header as $Computers
Will SzymkowskiSenior Solution ArchitectCommented:
You need to make sure that Name is the heading. That should then work for you.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.