Example of converting an object to a string output using the out-string command in PowerShell _powershell

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.