How can i get the object information of a list of servers from powershell

I have a list of over 20 servers need to know their current OU/location and move them to a new OU.

I already used the following command to collect these servers, but i don't know which command I need use to get their current object/OU information, can someone here help?

Thanks.

PS C:\Windows\system32> Get-ADComputer -Filter {Name -like "*host*"} | select Name

Name
----
DAL-OHOST-FS
MIA-OHOST-01
STA-OHOST-01
VCR-OHOST-01
BPDR-OHOST-01
MTY-OHOST-01
NVA-OHOST-01
PRI-OHOST-01
PRI-1D-SCHOSTAG
DUR-OHOST-01
HOU-OHOST-FS
SFO-OHOST-01
ATL-OHOST-01
WAL-OHOST-01
PHI-OHOST-01
BOS-OHOST-01
MTL-OHOST-01
DAL-OHOST-01
CAL-OHOST-01
HOU-OHOST-01
WDC-OHOST-01
MCL-OHOST-01
LOM-OHOST-01
CHI-OHOST-01
MEX-OHOST-01
MIN-OHOST-01
NA-EXCHHOST-01
GLN-OHOST-01
NYC-OHOST-01
LAX-OHOST-01
TOR-OHOST-01
BUR-OHOST-01
TDC-OHOST-01
POR-OHOST-01
DA3-OHOST-01
CBS-OHOST-01
PRI-1B-SCHOSTAG
Jason YuAsked:
Who is Participating?
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.

Chris DentPowerShell DeveloperCommented:
DistinguishedName.
Get-ADComputer -Filter {Name -like "*host*"} | select Name, DistinguishedName

Open in new window

That value describes the full path in the directory. You also get the location from canonicalName, but that's no really much good other than looking prettier.
Get-ADComputer -Filter {Name -like "*host*"} -Properties canonicalName | select Name, DistinguishedName, canonicalName

Open in new window

However, you don't actually need any of that when moving things unless there's another reason you want it?

Chris

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
footechCommented:
Just by looking at the DistinguishedName property instead of the Name property you can see their OU.  So you could just change the Select-Object command.

To move objects, you can pipe directly from the Get-ADComputer cmdlet to Move-ADObject.
Get-ADComputer -Filter {Name -like "*host*"} | Move-ADObject -TargetPath "OU=someOU,DC=domain,DC=com"

Open in new window

Jason YuAuthor Commented:
could you give me an example of using Move-ADObject for my case?
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

Chris DentPowerShell DeveloperCommented:
footech has provided an example of the move operation already.

Chris
Jason YuAuthor Commented:
Thanks, I appreciate your help.
Jason YuAuthor Commented:
Hi, Chris and Footech, thank you two very much, I learned it.

BTW, if I want to learn powershell from the most basic step, where should I begin?
Chris DentPowerShell DeveloperCommented:
I've heard reasonably good things about this one, a few people I know used it to get started:

http://www.amazon.co.uk/Learn-Windows-PowerShell-Month-Lunches/dp/1617290211

There's a lot to be said for experimenting as well (I come from that school, never read any of the books). For the things you might do manually think how you might do them in PowerShell instead. AD is a good technology to work with for this, there's lots you can do (especially searching and reporting) by extending on the commands above.

Inside PowerShell there's help available too, for example, if you wanted to know what else was available in the Active Directory module you might run:
Get-Command -Module ActiveDirectory

Open in new window

Of course, don't forget Get-Help (or Get-Help -Examples if you want to skip right to that). Commands tend to be pretty predictably named, plenty of room for exploration.

Chris
footechCommented:
I've never read any books either (though I've heard the one above mentioned plenty).

If you get into the habit of reading the built-in help, I think it will help you down the road for all the times when you can't remember exactly how the parameter works or what it's name is.   Even reading the help for cmdlets you're familiar with can reveal different ways of using it, or parameters you had forgotten about.

I like the "Hey, Scripting Guy!" blog posts.

I think the best thing for learning is to pick issues that you're motivated to solve.  Sometimes they could be issues you're facing, other times things you think you should know.  I know I learned a lot by solving/investigating users' questions on Experts Exchange.  I was more motivated to help them solve a problem than just gathering theoretical knowledge.
Jason YuAuthor Commented:
thanks, I will read this book for begining.

have a nice day!
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
Powershell

From novice to tech pro — start learning today.