Export (0) Print
Expand All

Custom Host

Host applications can use the host that is provided by Windows PowerShell, or they can create a custom host by implementing their own host classes. The host is the component of Windows PowerShell that provides communications between the user and the Windows PowerShell engine. This communications includes dialog-oriented functionality, such as what types of prompts are used, and low-level functionality, such as what color the displayed text is rendered in.

Windows PowerShell provides a $Host environment variable that can be used to access the properties of the host from the command line. Scripts can access the host through the $host variable. Cmdlets that derive from the PSCmdlet class can access the host through their Host property.

Host Classes and Interfaces

To create a custom host, you must implement one or more of the following host classes or interfaces.

Serves as a base class for creating a custom host. For a template of a basic host class implementation, see How to Implement a Custom Host.

Defines the custom host functionality that is used to perform dialog-oriented and line-oriented interaction, such as writing to, prompting for, and reading from user input.

Defines the low-level custom host functionality, such as read and write actions, that a host application can implement to support character-mode interaction with the user.

Provides support for opening and closing, entering and exiting, a PSSession on a computer.

Provides a set of choices that enable the user to choose one or more options.

Adding a Custom Host

To add a custom host, you must implement one or more of the host classes or interfaces described in the previous section, and then create a runspace that uses the custom host. For an example of adding a custom host, see How to Add a Custom Host.

Custom Host Samples

For complete samples of console applications that implement custom hosts, see Custom Host Samples.

See Also

© 2014 Microsoft