PowerShell Logo Small

Out-String



This is the built-in help made by Microsoft for the command 'Out-String', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Sends objects to the host as a series of strings.

SYNTAX


Out-String [-InputObject <psobject>] [-Stream] [-Width <int>] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Out-String cmdlet converts the objects that Windows PowerShell manages into an array of strings. By default, Out-String accumulates the strin
gs and returns them as a single string, but you can use the stream parameter to direct Out-String to return one string at a time. This cmdlet let
s you search and manipulate string output as you would in traditional shells when object manipulation is less convenient.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkID=113368
Out-File
Out-Null
Out-Host
Out-Printer
Out-Default

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

C:\PS>get-content C:\test1\testfile2.txt | out-string



Description
-----------
This command sends the content of the Testfile2.txt file to the console as a single string. It uses the Get-Content cmdlet to get the content of
the file. The pipeline operator (|) sends the content to Out-String, which sends the content to the console as a string.








-------------------------- EXAMPLE 2 --------------------------

C:\PS>$c = get-culture | select-object *

C:\PS> out-string -inputobject $c -width 100



Description
-----------
These commands get the regional settings for the current user and convert the data to strings. The first command uses the Get-Culture cmdlet to g
et the regional settings. The pipeline operator (|) sends the result to the Select-Object cmdlet, which selects all properties (*) of the culture
object that Get-Culture retrieved. The command then stores the results in the $c variable.

The second command uses Out-String to convert the CultureInfo object to a series of strings (one string for each property). It uses the InputObje
ct parameter to pass the $c variable to Out-String. The width parameter is set to 100 characters per line to prevent truncation.








-------------------------- EXAMPLE 3 --------------------------

C:\PS>get-alias | out-string -stream | select-string "Get-Command"



Description
-----------
This command displays aliases that include the phrase "Get-Command". It uses the Get-Alias cmdlet to get a set of AliasInfo objects (one for each
alias in the current session). This example demonstrates the difference between working with objects and working with strings.

The pipeline operator (|) sends the output of Get-Alias to Out-String, which converts the objects to a series of strings. It uses the Stream para
meter to send each string individually, instead of concatenating them into a single string. Another pipeline operator sends the strings to Select
-String, which selects the strings that include "Get-Command" anywhere in the string.

If you omit the Stream parameter, the command displays all of the aliases, because Select-String finds "Get-Command" in the single string that Ou
t-String returns, and the formatter displays the string as a table.