Contact Info

Crumbtrail » Administration » Powershell » Powershell 1.0 » Out-String

Out-String - Powershell 1.0 CmdLet

Microsoft Windows PowerShell is a command-line shell and scripting tool based on the Microsoft .NET Framework. It is designed for system administrators, engineers and developers to control and automate the administration of Windows and applications.

More than hundred command-line tools (so called "cmdlets") can be used to perform system administration tasks and Windows Management Instrumentation (WMI). These cmdlets are easy to use, with standard naming conventions and common parameters, and standard tools for piping, sorting, filtering, and formatting data and objects.


Send objects to the host as strings


-inputObject psobject
       The object to be written to file. {may be piped}
       A command, expression or variabale that contains the objects.
   -width int
       The number of characters in each line of output. 
       Any additional characters are truncated, not wrapped.
       The default is determined by the host, for PowerShell.exe
       this is 80 (characters).
       Send the strings for each object separately. 
       By default, the strings for each object are accumulated
       and sent as a single string.
       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutVariable.

Send the content of Test1.txt to the console as a single string:

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

Get the regional settings for the current user and convert the data to strings:

PS C:\>$cult = get-culture | select-object *
out-string -inputobject $cult -width 100

Display all aliases that include the phrase "Get-"

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

Piping into Select-String demonstrates the difference between working with objects and working with strings. The -stream parameter sends each string individually, as without this Select-String would simply match and return the entire single string containing all of the aliases.