Solved

Reboot all computer is OU at TIME

Posted on 2016-09-12
5
57 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Set OWA language and time zone in Exchange for individuals, all users or per database.
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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