Created
February 18, 2020 23:41
-
-
Save iyre/da490c0d941625f5a1a1aa1dbfa8ef75 to your computer and use it in GitHub Desktop.
Remotely shut down all active computers on a domain
This file contains hidden or 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
# Shuts down computers without notice | |
$DateOffset = 30 | |
$StartDate = (Get-Date).AddDays(-($DateOffset)) | |
$SearchBase = "OU=Domain Computers, DC=contoso, DC=com" | |
Get-ADComputer -Filter { | |
( LastLogonDate -gt $StartDate ) -and | |
( Name -ne "$env:COMPUTERNAME" ) | |
} -SearchBase $SearchBase -Properties LastLogonDate | | |
Foreach-Object { Stop-computer -ComputerName $_.Name -Force -AsJob } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment