- 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 use the ConvertFrom-StringData command in PowerShell?
The ConvertFrom-String command converts the String to the Hashtable format as shown below.
Example
PS C:\> "This is string" | ConvertFrom-String
Output
P1 P2 P3 -- -- -- This is string
In the above example, We haven’t specified any header so that the output is separated the delimiter by space P1, P2 and continuous. By default, this command separates the string with a ‘=’ delimiter as shown below.
Example
$stringhash = @" Name = Spooler Starttype = Manual Status = Stopped "@ $stringhash | ConvertFrom-StringData
Output
Name Value ---- ----- Status Stopped Starttype Manual Name Spooler
Another method we can use is by separating string Keys and values with a delimiter parameter. This parameter is only available in the PowerShell core 7.1 version.
Example
$stringhash = @" Name | Spooler Starttype | Manual Status | Stopped "@ ConvertFrom-StringData -StringData $stringhash -Delimiter '|'
We can also use the below method.
PS C:\> $stringhash = "Name = Spooler `n StartType = Manual `n Status = Stopped" PS C:\> ConvertFrom-StringData -StringData $stringhash Name Value ---- ----- Status Stopped Name Spooler StartType Manual
Advertisements