Solved

Reboot all computer is OU at TIME

Posted on 2016-09-12
5
100 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A brief introduction to what I consider to be the best editor for PowerShell.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

707 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