Updated: August 9, 2015
The Get-Host cmdlet gets an object that represents the program that is hosting Windows PowerShell.
The default display includes the Windows PowerShell version number and the current region and language settings that the host is using, but the host object contains a wealth of information, including detailed information about the version of Windows PowerShell that is currently running and the current culture and UI culture of Windows PowerShell. You can also use this cmdlet to customize features of the host program user interface, such as the text and background colors.
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
The input type is the type of the objects that you can pipe to the cmdlet.
You cannot pipe input to this cmdlet.
The output type is the type of the objects that the cmdlet emits.
Get-Host returns a System.Management.Automation.Internal.Host.InternalHost object.
The $Host automatic variable contains the same object that Get-Host returns, and you can use it in the same way. Similarly, the $PSCulture and $PSUICulture automatic variables contain the same objects that the CurrentCulture and CurrentUICulture properties of the host object contain. You can use these features interchangeably.
For more information, see about_Automatic_Variables.
Example 1: Get information about the PowerShell console host
This command displays information about the Windows PowerShell console, which is the current host program for Windows PowerShell in this example. It includes the name of the host, the version of Windows PowerShell that is running in the host, and current culture and UI culture.
The Version, UI, CurrentCulture, CurrentUICulture, PrivateData, and Runspace properties each contain an object with very useful properties. Later examples examine these properties.
Example 2: Resize the PowerShell window
This command resizes the Windows PowerShell window to 10 pixels by 10 pixels.
Example 3: Get the PowerShell version for the host
This command gets detailed information about the version of Windows PowerShell running in the host. You can view, but not change, these values.
The Version property of Get-Host contains a System.Version object. This command uses a pipeline operator (|) to send the version object to the Format-List cmdlet. The Format-List command uses the Property parameter with a value of all (*) to display all of the properties and property values of the version object.
Example 4: Get the current culture for the host
This command gets detailed information about the current culture set for Windows PowerShell running in the host. This is the same information that is returned by the Get-Culture cmdlet.
Similarly, the CurrentUICulture property returns the same object that Get-UICulture returns.
The CurrentCulture property of the host object contains a System.Globalization.CultureInfo object. This command uses a pipeline operator (|) to send the CultureInfo object to the Format-List cmdlet. The Format-List command uses the Property parameter with a value of all (*) to display all of the properties and property values of the CultureInfo object.
Example 5: Get the DateTimeFormat for the current culture
This command returns detailed information about the DateTimeFormat of the current culture that is being used for Windows PowerShell.
The CurrentCulture property of the host object contains a CultureInfo object that, in turn, has many useful properties. Among them, the DateTimeFormat property contains a DateTimeFormatInfo object with many useful properties.
Example 6: Get the RawUI property for the host
This command displays the properties of the RawUI property of the host object. By changing these values, you can change the appearance of the host program.
Example 7: Set the background color for the PowerShell console
These commands change the background color of the Windows PowerShell console to black. The cls command is an alias for the Clear-Host function, which clears the screen and changes the whole screen to the new color.
This change is effective only in the current session. To change the background color of the console for all sessions, add the command to your Windows PowerShell profile.
Example 8: Set the background color for error messages
This command changes the background color of error messages to white.
This command uses the $Host automatic variable, which contains the host object for the current host program. Get-Host returns the same object that $Host contains, so you can use them interchangeably.
This command uses the PrivateData property of $Host as its ErrorBackgroundColor property. To see all of the properties of the object in the $Host.PrivateData property, type
$host.privatedata | format-list *.