Instantly share code, notes, and snippets.

Embed
What would you like to do?
Import-Module ActiveDirectory
$ou = "OU=Office Computers,Dc=CompanyName,Dc=Net"
Get-ADComputer -Filter * -SearchBase $ou |
ForEach-Object {
Restart-Computer -ComputerName $_.name -force
}
# If you wish to eliminate specific machines from this restart - no problem, you can add a "where" clause using a wildcard to either target an individual or complete OU.
Get-ADComputer -Filter * -SearchBase $ou | where { ($_.DistinguishedName -notlike "*OU=Display,*" -and $_.DistinguishedName -notlike "*BURSAR*") } |
ForEach-Object {
Restart-Computer -ComputerName $_.name -force
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment