ps/Modules/Alkami.DevOps.Inventory/Public/Get-WindowsServiceInventory.ps1
2023-05-30 22:51:22 -07:00

34 lines
1.2 KiB
PowerShell

function Get-WindowsServiceInventory {
<#
.SYNOPSIS
Returns an OrderedDictionary that Represents the Windows Service Inventory.
#>
[CmdletBinding()]
Param()
$logLead = (Get-LogLeadName);
$providerStopWatch = [System.Diagnostics.StopWatch]::StartNew()
$serviceDictionary = New-Object System.Collections.Specialized.OrderedDictionary
try {
Write-Verbose "$logLead : [$($providerStopWatch.Elapsed)] : Reading Windows Service Information"
$services = Get-CIMInstance -Namespace "root\CIMV2" -Class Win32_Service `
-Property Name, ProcessId, State, StartMode, Status, PathName, StartName, Description, DisplayName `
| Select-Object -Property Name, ProcessId, State, StartMode, Status, PathName, StartName, Description, DisplayName
Write-Verbose "$logLead : [$($providerStopWatch.Elapsed)] : Windows Service Information Retrieved"
$serviceDictionary.Add("Services", $services)
}
catch {
$serviceDictionary["Error"] = $_.Exception.ToString()
}
Write-Verbose "$logLead : [$($providerStopWatch.Elapsed)] : Provider Complete"
$providerStopWatch.Stop()
return $serviceDictionary
}