?
Solved

Reboot all computer is OU at TIME

Posted on 2016-09-12
5
Medium Priority
?
126 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 2000 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

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.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

770 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