Last active
July 31, 2020 20:08
-
-
Save iyre/008e15da26f923f27dd2d8db2ed58a0c to your computer and use it in GitHub Desktop.
Invoke commands on all active computers in 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
$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