This article describes how to convert an object that is output from a cmdlet to a string string type in PowerShell to facilitate later processing.
The results of the cmdlet output in PowerShell are in the form of objects (object). For object type, there are pros and cons in post-processing, of course, more advantages than disadvantages. But at some point, we want the result of the cmdlet output to be a string, so how do we implement it?
A Out-string cmdlet is provided in PowerShell to see its introduction: The Out-string cmdlet converts Windows PowerShell managed objects into string arrays. By default, out-string accumulates strings and returns them as a single string, but you can use the stream parameter to let out-string return a string at a time. This cmdlet is used to search for and manipulate string output as if object manipulation is not convenient, as in a traditional shell.
There are two main ways to use out-string, which is to automatically convert the output objects of other cmdlet to strings after placing out-string in the pipeline. Another way is to use the Inputobject parameter to assign the object to be converted as a variable to out-string.
Examples are as follows:
Copy Code code as follows:
$help =get-help Get-alias | Out-string
About PowerShell the output of the object into a string, this article on the introduction of so many, I hope to help you, thank you!