In this post, we will illustrate the “Out-String” cmdlet in PowerShell.
How to Use Out-String (Microsoft.PowerShell.Utility) Cmdlet in PowerShell?
To use the “Out-String” cmdlet in PowerShell, first, write the cmdlet or input that needs to be converted into a string. Then, place the pipeline with the “Out-String” cmdlet to perform the conversion. Let’s uncover details about the stated cmdlet with the aid of examples.
Example 1: Use the “Out-String” Cmdlet to Output it as a String
First, place the desired cmdlet whose output needs to be converted into a string. Then, pipe it to the “Out-String” cmdlet:
Example 2: Use the “Out-String” Cmdlet to Work with Objects
Execute this command to get an alias-related command in PowerShell:
Example 3: Use the “Out-String” Cmdlet to Save the Output to a File
To save the content of the particular cmdlet into a file, execute the provided cmdlet:
Now, run the provided command to verify whether the content was stored in a file or not:
That’s it! We have provided information about the “Out-String” cmdlet in PowerShell.
Conclusion
PowerShell’s “Out-String” cmdlet converts the input text, objects, or command into a string. Moreover, it can also format the output in the console. This post has elaborated on the “Out-String” cmdlet with the help of various examples.