How to list service properties for multiple services

I know I can get the status of a service using this command: get-wmiobject win32_service |where {$_.name -match "bits"} to return all the properties I need (Name, StartMode, and State).

   ExitCode  : 0
   Name      : BITS
   ProcessId : 820
   StartMode : Manual
   State     : Running
   Status    : OK

That's a good start, but what is the best way to pass a specific list of services to this, or some other similar command, to return  the multiple service statuses?

Thank you in advance for your time with this!  I appreciate it.

Roy.

Parents
No Data
Reply
  • Try this

    $services = "BITS", "Dnscache", "LanmanServer", "LanmanWorkstation", "RemoteRegistry", "W32Time", "Winmgmt", "WinRM"

    $services | foreach {Get-WmiObject -Class Win32_Service -Filter "Name = '$($_)'" | select Name, State }

     

    you could put the services in a csv file or make it one line

    "BITS", "Dnscache", "LanmanServer", "LanmanWorkstation", "RemoteRegistry", "W32Time", "Winmgmt", "WinRM" |
     foreach {Get-WmiObject -Class Win32_Service -Filter "Name = '$($_)'" | select Name, State }

    You can't use a direct pipeline because the Filter parameter doesn't accept pipeline input

    PS> Get-Help Get-WmiObject -Parameter Filter

    -Filter <string>
        Specifies a Where clause to use as a filter. Uses the syntax of the WMI Query Language (WQL).

        Important: Do not include the Where keyword in the value of the parameter. For example, the following commands return only the   logical disks that where the DeviceID equals 'c:' and the services where the name equals 'WinRM', without using the Where keyword:

        get-WmiObject Win32_LogicalDisk -filter "DeviceID = 'c:' "
        get-wmiobject win32_service -filter "name='WinRM'"

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?       false
        Accept wildcard characters?  false

     

Children
No Data