Skip to content

Instantly share code, notes, and snippets.

@iyre
Last active July 31, 2020 20:08
Show Gist options
  • Save iyre/008e15da26f923f27dd2d8db2ed58a0c to your computer and use it in GitHub Desktop.
Save iyre/008e15da26f923f27dd2d8db2ed58a0c to your computer and use it in GitHub Desktop.
Invoke commands on all active computers in a domain
$ProcessName = "outlook"
$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 |
Foreach-Object {
Invoke-Command -ComputerName $_.Name -ScriptBlock {
Get-Process -Name $args[0] | Stop-Process -Force
} -ArgumentList $ProcessName -AsJob
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment