PowerShell: Output Windows Services to JSON file

A simple one-liner for outputting Windows Service properties to a JSON file.

Get-Service * | ConvertTo-Json | Out-File services.json

And here are some approaches for getting string representations of the enum integers:
[Stack Overflow] Powershell – Retain Complex objects with ConvertTo-Json
https://stackoverflow.com/questions/44516308/powershell-retain-complex-objects-with-convertto-json

 

Alternative command using Get-WmiObject — this doesn’t require any enum serialisation workarounds:

Get-WmiObject win32_service | ConvertTo-Json > services.json

Leave a Reply

Your email address will not be published. Required fields are marked *