Author Posts

February 3, 2014 at 2:22 am

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)
             }

February 3, 2014 at 3:32 am

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

February 3, 2014 at 4:42 am

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.

February 4, 2014 at 1:13 am

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.