Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cls
- $Servicelist = @("WinRM", "Winmgmt", "DHCP") #Services are declared here, but you can of course load them from something like a CSV file.
- $Computerlist = @("LocalHost", "Server1","Server2","Server3") #Computers are declared here, but you can of course load them from something like a CSV file.
- #HashTable, wil store the services with running status for each server,
- $ServiceStatus = @{}
- #Computer loop
- Foreach ($Computer in $Computerlist)
- {
- #Retrieve al services from computer and extract specified services.
- $ServicesFound = Get-Service <#-ComputerName $Computer#> | Where-Object {$Servicelist -contains $_.Name} | Select Name, Status
- #Loop trough the found sercices.
- Foreach ($Service in $ServicesFound)
- {
- #If service is not yet declared, then do so and add the computer status.
- If(!($ServiceStatus["$($Service.Name)"])) {
- $ServiceStatus["$($Service.Name)"] = $Service | Select @{N='Service'; E={$($Service.Name)}}, @{N="$Computer"; E={$Service.Status}}
- }
- #If service is already declared, then only add the current computer status to it.
- else {
- $ServiceStatus["$($Service.Name)"] = $ServiceStatus["$($Service.Name)"] | Select *, @{N="$Computer"; E={$Service.Status}}
- }
- }
- }
- # Export as HTML
- $ServiceStatus.Values | ConvertTo-Html -Fragment
- # Export as Objects
- $ServiceStatus.Values
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement