March 23rd, 2014

PowerTip: Create XML with PowerShell

Doctor Scripto
Scripter

Summary: Use Windows PowerShell to create XML.

Hey, Scripting Guy! Question How can I use Windows PowerShell to easily create an XML representation of my service names and status?

Hey, Scripting Guy! Answer Use the Get-Service cmdlet to retrieve the service information, select the name and status properties,
          and pipe the results to the ConvertTo-XML cmdlet. Then to facilitate post processing of the information,
          store the results in a variable:

$xml = Get-Service | select name, Status | ConvertTo-Xml

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.