Cmdlet listing services' "manufacturer"

This topic contains 3 replies, has 3 voices, and was last updated by  Ayan Mullick 3 years, 10 months ago.

  • Author
    Posts
  • #12897

    Ayan Mullick
    Participant

    Is there a way to list the services' manufacturer in powershell in a similar format ?

    I could come this far. However, this doesn't work for all the services

    foreach ($item in get-wmiobject win32_service) 
               {Write-Host 
                    $Item.Name,'
                    $item.StartMode,$item.State,'
                    $(get-childitem -path ($item.pathname -replace '"','' )|'
    
                         select-object -expand VersionInfo | '
    
                         select-object -expand CompanyName -ErrorAction Stop)
                 }
  • #12899

    Richard Siddaway
    Moderator

    First off never use Write-Host like this – you should be outputting objetcs
    Secondly you never use a backtick after a pipe symbol – the pipe is a line continuation character in its own right
    Thirdly your -ErrorAction Stop should be on the get-childitem command not the select
    Fourthly you should use get-item not get-childitem

    Having said all that you are very close to the solution

    foreach ($service in Get-WmiObject -Class Win32_Service) {
    $props = [ordered]@{
    Name = $service.Name
    StartMode = $service.StartMode
    Status = $service.State
    Manufacturer = ""
    }
    if ($service.PathName -like "*system32\svchost.exe*") {
    $props.Manufacturer = "Microsoft"
    }
    else {
    $path = ($service.PathName -split " /")[0]
    $path = $path.Replace('"', '')
    $props.Manufacturer = (Get-Item -Path $($path) |
    select -ExpandProperty versioninfo |
    select -ExpandProperty CompanyName )
    }
    New-Object -TypeName PSObject -Property $props
    }

    I've not given a full solution because many services run under C:\windows\System32\svchost.exe. You'll need to dig into those processes and see what can be discovered

    • #12924

      Ayan Mullick
      Participant

      Thank you Richard for the pointers. I'll keep in mind.
      And I am mainly looking to retrieve the names, status, start-modes and Manufacturer of the 3rd party services running on a box that'll help me create a cmdlet to clean-boot the server.

  • #12904

    Dave Wyatt
    Moderator

    For shared services that run under svchost.exe, there will be a path to a DLL file under Parameters\ServiceDll in the registry. I'm not sure if you'll be able to get useful data from VersionInfo.CompanyName of the DLL the same way you're doing for services that have their own process, but it's worth a shot.

You must be logged in to reply to this topic.