-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForceCloseApp
29 lines (23 loc) · 996 Bytes
/
ForceCloseApp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$ADcomputers = Get-ADComputer -SearchBase "DC=company,DC=edu" -Filter {Enabled -eq $True -and OperatingSystem -notlike '*Server*'} | forEach-Object {$_.Name}
$PingCompList = $ADcomputers | Invoke-Ping
$User = "domain\user"
$Pass = ConvertTo-SecureString "Passwowrd" -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $User,$Pass
$command = { $ZoomProc = Get-Process -name Zoom -ErrorAction "Ignore"
if ($ZoomProc -ne $null) {
echo "Stopping Zoom..."
Stop-Process -Name Zoom
} else {
echo "No running Zoom process found"
}
}
foreach ($computer in $PingCompList){
if ($computer.STATUS -eq "Responding")
{
Invoke-Command -AsJob -ComputerName $computer.Address -ScriptBlock $command -Credential $Credentials
write-host -foregroundcolor "Green" "Running on: " $computer.Address
}
else{
Write-host -foregroundcolor "Red" $computer.Address "is offline" -InformationAction Ignore
}
}