Last active
October 18, 2017 22:46
-
-
Save midnightfreddie/d317d151dc28d8244eea8ebb9b70c8ba to your computer and use it in GitHub Desktop.
In reply to https://www.reddit.com/r/PowerShell/comments/76zbc0/if_two_services_are_running_print_computername/
This file contains 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
$Services = @( | |
"netlogon" | |
"spooler" | |
) | |
$Computers = @( | |
"." | |
"iis" | |
) | |
Get-Service -Name $Services -ComputerName $Computers -ErrorAction SilentlyContinue | | |
Where-Object { $PSItem.Status -eq "Running" } | | |
Group-Object -Property MachineName | | |
Where-Object { $PSItem.Count -ge $Services.Count } | | |
Select-Object -ExpandProperty Name | | |
ForEach-Object { | |
Write-Output ("$PSItem is running " + ($Services -join " and ") ) | |
} |
This file contains 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
$Services = @( | |
"netlogon" | |
"spooler" | |
) | |
$Computers = @( | |
"." | |
"iis" | |
) | |
$Computers | ForEach-Object { | |
if (( | |
Get-Service -Name $Services -ComputerName $PSItem -ErrorAction SilentlyContinue | | |
Where-Object { $PSItem.Status -eq "Running" } | |
).Count -ge $Services.Count) { | |
Write-Output ("$PSItem is running " + ($Services -join " and ") ) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment