Author Posts

April 28, 2016 at 5:48 am

Hi ,
I am a starter in Power shell scripting..
I am trying to retrieve the list of OS related and Non -OS related service..from n no. of Servers.
Do we have any cmdlet for the same, if not.. how I can bifurcate the same.

As in service console, I can see all Win32 related services are stored on C:\windows\system32
and any Non-OS like anti-virus or any other application used to store in C:\program\... filed
Please suggest..

April 28, 2016 at 5:55 am

Get-Service or WMI's Win32_Service

April 28, 2016 at 6:02 am

hey Rob,
Thanks for heading up..

Gsv or gmi win32_service will list all services.. including the third party apps too. I wants bifurcation for the same... like win32 servicess and apps services..

April 28, 2016 at 8:04 am

Your problem is identifying the 'non-OS' services. There isn't a flag on the service object to indicate where it came from

If you use
Get-CimInstance Win32_Service | select Caption, PathName

You'll see that many services have a path that starts C:\windows\system32\...
That's probably your best bet but its not infallible e.g.
Windows Modules Installer has a path of C:\WINDOWS\servicing\TrustedInstaller.exe

May 1, 2016 at 12:57 am

Thanks Richard..
Get-CimInstances win32_service is much better option.

I am using this option for getting a OS and Non -OS services from a list of server.

function Get-OSandNonOSservices
[Parameter(Mandatory=$true, Position=0,
ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]

process {
foreach ($c in $ComputerName) {
$Osservices = (get-CimInstance Win32_Service -ComputerName $c) | select Caption, PathName | sort-object pathname | where {$_.Pathname -like "C:\Windows\*.*"} | Select Caption
$NonOsservices = (get-CimInstance Win32_service -ComputerName $c) | Select Caption, PathName | where {$_.PathName -notlike "C:\Windows\*.*"} | select Caption

new-object psobject -prop @{

ComputerName = $c
OSServices = $Osservices
NonOSServices = $NonOsservices
cat '.\computername.txt' | Get-OSandNonOSservices | Format-table | out-file -filepath "D:\Test\AllServices.csv"

but I am not sure why this -computername is not appearing for .. Get-CimInstances win32_service

May 4, 2016 at 8:06 am

Any one can help me out here..

Though i am importing a list of servers services , but the result is showing only for one server.
I tried for get-CimInstance Win32_Service. please help.

(Import-Csv "D:\Test\serverlist.csv") | forEach-Object {
$ListofOsservice = Get-Service -ComputerName $_.ServerName | Select-Object -Property DisplayName,ServiceType | Where-Object {$_.ServiceType -like "Win32ShareProcess"}| Select DisplayName
$NonOsservices = Get-Service -ComputerName $_.ServerName | Select-Object -Property DisplayName,ServiceType | Where-Object { $_.ServiceType -notlike "Win32ShareProcess"} | Select DisplayName
######## "This is a list of Osservices"
$listofOsservice | Format-table | Out-file -FilePath "D:\Test\Osservices.txt"
########## "This is a list of Non-Osservices"
$NonOsservices | Format-Table | Out-file -FilePath "D:\Test\NonOsservices.txt

May 4, 2016 at 8:44 am

The reason is that as you are going through the loop you are overwriting you $ListofOsService and $NonOsServices. When you complete the loop you only have the two objects. Not everything you pulled in the loop.

Move your Out-File into the loop and add -Append and you will get them all like you intend.

May 4, 2016 at 9:54 am

Excellent Paul.. it works ..bit more... I want to display the server name and their respective services as a display name ..