- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert command output to the Hashtable format in PowerShell?
To convert any command output to the hashtable in PowerShell, we can first convert the output to the JSON format using the ConvertTo-JSON command, and applying the ConvertFrom-JSON command from the first output will produce an output to the Hashtable.
Example
Get-Service
The above command will give the output in the array format.
Output
Status Name DisplayName ------ ---- ----------- Stopped WwanSvc WWAN AutoConfig Stopped XblAuthManager Xbox Live Auth Manager Stopped XblGameSave Xbox Live Game Save Stopped XboxGipSvc Xbox Accessory Management Service Stopped XboxNetApiSvc Xbox Live Networking Service
To convert the above output into the hashtable use the below command,
Example
Get-Service | ConvertTo-Json | ConvertFrom-Json
When you use the above command, it exposes all the properties. To get only a few properties, use the select command.
Get-Service | ConvertTo-Json | ConvertFrom-Json | Select Name, DisplayName, Status, Startype, DependentServices Name : XblAuthManager DisplayName : Xbox Live Auth Manager Status : 1 Startype : DependentServices : {System.ServiceProcess.ServiceController} Name : XblGameSave DisplayName : Xbox Live Game Save Status : 1 Startype : DependentServices : {}
You can now store the output and play it like a Hashtable.
- Related Articles
- How to convert the hashtable to the JSON format using PowerShell?
- How to convert JSON object to Hashtable format using PowerShell?
- How to convert Dictionary to Hashtable in PowerShell?
- How to get process output in GridView format in PowerShell ?
- How to exclude PSComputerName property from Invoke-Command output in PowerShell?
- How to exclude the RunSpaceID property from the Invoke-Command output in PowerShell?
- How to use Hashtable splatting in PowerShell?
- How to sort the output in PowerShell?
- How to Convert Hashtable to String?
- How to add multiple values in the Hashtable using PowerShell?
- Difference between Write-Output and Write-Host command in PowerShell?
- MySQL convert timediff output to day, hour, minute, second format?
- How to use the tree command in PowerShell?
- How to use the Timeout command in PowerShell?
- How to export output to excel in PowerShell?

Advertisements