I have pretty simple code that iterates over the output of Get-Service | Select Name, DisplayName, Status
and then formats it into a json object. The problem I am facing is running that command outside of my powershell script returns the actual textual status (RUNNING, STOPPED, etc), but in the script the status is numeric (1-4). I am currently running PS Version 5.1.18362.145
Script:
$services = Get-Service | Select Name, DisplayName, Status
$services.ForEach({
Add-Member -NotePropertyName 'table' -NotePropertyValue 'Status' -InputObject $_;
})
$payload = @{
metrics = @($services)
} | ConvertTo-Json
Write-Output ($payload)
Example Output:
{
"Name": "WPDBusEnum",
"DisplayName": "Portable Device Enumerator Service",
"Status": 1,
"table": "Status"
},
{
"Name": "WpnService",
"DisplayName": "Windows Push Notifications System Service",
"Status": 4,
"table": "Status"
},
{
"Name": "WpnUserService_8be1a",
"DisplayName": "Windows Push Notifications User Service_8be1a",
"Status": 4,
"table": "Status"
}
I would prefer for Status
to remain textual instead of numeric. Is this something specific to PS 5?