Created
October 1, 2018 19:52
-
-
Save normansolutions/3609052ae35a51aa95cb5c5056f4e55f to your computer and use it in GitHub Desktop.
For use on blogpost https://normansolutions.co.uk/blog/encourage-those-windows-to-restart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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