Solved

Reboot all computer is OU at TIME

Posted on 2016-09-12
5
36 Views
Last Modified: 2016-09-12
Can someone tell me why this is failing (and how to fix it)??

Get-ADComputer -Filter * -SearchBase "OU=Test, OU=Hanger,OU=Planes Computers,DC=notmydomain,DC=com" |restart-computer $_.name


I have confirmed the first part works.  As a minor side question, how could I get the first part to output only the name with no title like "BOB" and not "Name: BOB"


Thanks for your help!!!
0
Comment
Question by:loftyworm
  • 3
  • 2
5 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 41794305
Try..
Restart-Computer -ComputerName (Get-ADComputer -Filter * -SearchBase "OU=Test, OU=Hanger,OU=Planes Computers,DC=notmydomain,DC=com" | Select -exp Name)

Open in new window

Or..
Get-ADComputer -Filter * -SearchBase "OU=Test, OU=Hanger,OU=Planes Computers,DC=notmydomain,DC=com" | %{Restart-Computer -ComputerName $_.Name}

Open in new window

1
 
LVL 11

Author Comment

by:loftyworm
ID: 41794322
Thank you I will
Any thought on my second minor question?  what I should be learning??
0
 
LVL 11

Author Comment

by:loftyworm
ID: 41794339
Well, I tested this with replacing the restart with write-host, and it seemed to work.  I will set up my OU again, and test the restart :)
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41794351
Any thought on my second minor question?  what I should be learning??
You can just expand the name property to get only names..
Get-ADComputer -Filter * -SearchBase "OU=Test, OU=Hanger,OU=Planes Computers,DC=notmydomain,DC=com" | Select -ExpandProperty Name

Open in new window

Or use foreach to print just value..
Get-ADComputer -Filter * -SearchBase "OU=Test, OU=Hanger,OU=Planes Computers,DC=notmydomain,DC=com" | ForEach-Object {$_.Name}

Open in new window


Here $_.Name represent the value of the property Name.
0
 
LVL 11

Author Closing Comment

by:loftyworm
ID: 41794393
Fast and accurate, even with the follow up, THANK YOU!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
A procedure for exporting installed hotfix details of remote computers using powershell
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now