Avatar of Jason Yu
Jason Yu
Flag for United States of America asked on

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
Powershell

Avatar of undefined
Last Comment
Jason Yu

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Chris Dent

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
footech

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Jason Yu

ASKER
could you give me an example of using Move-ADObject for my case?
Chris Dent

footech has provided an example of the move operation already.

Chris
Jason Yu

ASKER
Thanks, I appreciate your help.
Your help has saved me hundreds of hours of internet surfing.
fblack61
Jason Yu

ASKER
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 Dent

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
footech

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Jason Yu

ASKER
thanks, I will read this book for begining.

have a nice day!