Getting OS related service and Non-OS related servie

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…

Get-Service or WMI’s Win32_Service

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…

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

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
{
param(
[Parameter(Mandatory=$true, Position=0,
ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
[ValidateNotNull()]
[string[]]$ComputerName
)

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

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

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.

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