Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Reboot all computer is OU at TIME

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
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…
Screencast - Getting to Know the Pipeline

610 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