Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. cls
  2. $Servicelist = @("WinRM", "Winmgmt", "DHCP") #Services are declared here, but you can of course load them from something like a CSV file.
  3. $Computerlist = @("LocalHost", "Server1","Server2","Server3") #Computers are declared here, but you can of course load them from something like a CSV file.
  4.  
  5. #HashTable, wil store the services with running status for each server,
  6. $ServiceStatus = @{}
  7.  
  8. #Computer loop
  9. Foreach ($Computer in $Computerlist)
  10. {
  11.  
  12. #Retrieve al services from computer and extract specified services.
  13. $ServicesFound = Get-Service <#-ComputerName $Computer#> | Where-Object {$Servicelist -contains $_.Name} | Select Name, Status
  14.  
  15. #Loop trough the found sercices.
  16. Foreach ($Service in $ServicesFound)
  17. {
  18.  
  19. #If service is not yet declared, then do so and add the computer status.
  20. If(!($ServiceStatus["$($Service.Name)"])) {
  21. $ServiceStatus["$($Service.Name)"] = $Service | Select @{N='Service'; E={$($Service.Name)}}, @{N="$Computer"; E={$Service.Status}}
  22. }
  23.  
  24. #If service is already declared, then only add the current computer status to it.
  25. else {
  26. $ServiceStatus["$($Service.Name)"] = $ServiceStatus["$($Service.Name)"] | Select *, @{N="$Computer"; E={$Service.Status}}
  27. }
  28. }
  29. }
  30.  
  31. # Export as HTML
  32. $ServiceStatus.Values | ConvertTo-Html -Fragment
  33.  
  34. # Export as Objects
  35. $ServiceStatus.Values
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement