Skip to content

Instantly share code, notes, and snippets.

@iyre
Created February 18, 2020 23:41
Show Gist options
  • Save iyre/da490c0d941625f5a1a1aa1dbfa8ef75 to your computer and use it in GitHub Desktop.
Save iyre/da490c0d941625f5a1a1aa1dbfa8ef75 to your computer and use it in GitHub Desktop.
Remotely shut down all active computers on a domain
# 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