Saturday, 22 May 2010

Get-ServiceDetails.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays service details 
  4. .DESCRIPTION 
  5.     This script first enumerates all the service controllers (ie services) 
  6.     running on the local system. For each service, we look into WMI and 
  7.     get info about that running service. 
  8. .NOTES 
  9.     File Name  : Get-ServiceDetails.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell Version 2.0 
  12. .LINK 
  13.     This script posted to: 
  14.         http://pshscripts.blogspot.com/2010/05/get-servicedetailsps1.html 
  15.     MSDN Sample posted at: 
  16.         http://msdn.microsoft.com/en-us/library/hde9d63a.aspx   
  17. .EXAMPLE 
  18.     PSH [C:\foo]: .\Get-ServiceDetails.ps1' 
  19.     Services running on the local computer: 
  20.  
  21.       Service :        AeLookupSvc 
  22.         Display name:    Application Experience 
  23.         Start name:      localSystem 
  24.         Description:     Processes application compatibility cache requests for applications as they are launched 
  25.  
  26.       Service :        AppHostSvc 
  27.         Display name:    Application Host Helper Service 
  28.         Start name:      LocalSystem 
  29.         Description:     Provides administrative services for IIS, for example configuration history and Applicati 
  30. on Pool account mapping. If this service is stopped, configuration history and locking down files or directori 
  31. es with Application Pool specific Access Control Entries will not work. 
  32. <rest snipped to save space!> 
  33. #> 
  34.  
  35. ## 
  36. # Start of script 
  37. ## 
  38.   
  39. # Load assembly with ServiceProcess class 
  40. $result = [reflection.Assembly]::LoadWithPartialName("System.ServiceProcess"
  41. $Services = [System.ServiceProcess.ServiceController]::GetServices() 
  42.   
  43. # Get WMI Services 
  44. $WMIServices = gwmi win32_service 
  45. # Display the list of services currently running on this computer. 
  46.   
  47. "Services running on the local computer:" 
  48. foreach ($Service in $Services) { 
  49.   
  50. if ($Service.Status -eq [system.ServiceProcess.ServiceControllerStatus]::Running)  { 
  51.   # Write the service name and the display name 
  52.   # for each running service. 
  53.   "" 
  54.   "  Service :        {0}"      -f  $Service.ServiceName 
  55.   "    Display name:    {0}"    -f  $Service.DisplayName 
  56.   # query WMI for more info on service 
  57.   $svc = $wmiServices  | where {$_.name -eq $service.servicename}   
  58.   "    Start name:      {0}"    -f  $Svc.StartName 
  59.   "    Description:     {0}"    -f  $Svc.Description 
  60. # End 

No comments: