CmdID / PowerShell / Cmdlets / Out
Out-String
Outputs input objects as a string. PowerShell reference
From the PowerShell reference 3 parameters
What it does
Outputs input objects as a string. The Out-String cmdlet converts input objects into strings. By default, Out-String accumulates the strings and returns them as a single string, but you can use the Stream parameter to direct Out-String to return one line at a time or create an array of strings. This cmdlet lets you search and manipulate string output as you would in traditional shells when object manipulation is less convenient. PowerShell also adds the oss function that calls Out-String -Stream as a shorthand way to use Out-String in a pipeline.
Out-String [-Stream] [-Width <Int32>] [-InputObject <PSObject>] [<CommonParameters>]
Get the current culture and convert the data to strings
$C = Get-Culture | Select-Object -Property *
Out-String -InputObject $C -Width 100IdentifyWorking with objects
Get-Alias | Out-String -Stream | Select-String -Pattern "gcm"IdentifyUse the Width parameter to prevent truncation.
PS> @{TestKey = ('x' * 200)} | Out-String
Name Value
---- -----
TestKey xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
PS> @{TestKey = ('x' * 200)} | Out-String -Width 250
Name Value
---- -----
TestKey xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxIdentifyIts page in the reference: Out-String.
Parameters
-InputObjectSpecifies the objects to be written to a string. Enter a variable that contains the objects, or type a command or expression that gets the objects.-StreamBy default, Out-String outputs a single string formatted as you would see it in the console
including any blank headers or trailing newlines. The Stream parameter enables Out-String to
output each line one by one. The only exception to this are multiline strings. In that case,
Out-String will still output the string as a single, multiline string.-WidthSpecifies the number of characters in each line of output. Any additional characters are wrapped to the next line or truncated depending on the formatter cmdlet used. The Width parameter applies only to objects that are being formatted. If you omit this parameter, the width is determined by the characteristics of the host program. In terminal (console) windows, the current window width is used as the default value. PowerShell console windows default to a width of 80 characters on installation.