Topic: Get-Host
Alias: None
On the surface the cmdlet Get-Host could easily be mistaken for a simple .exe like hostname.exe (which returns the local machine name and resides in C:WindowsSystem32 as well as C:WindowsSysWOW64). In PowerShell, a host represents the application running (hosting) the instance of Windows PowerShell. So, for instance, in my console host I can run this cmdlet and get the following results:
When you start to dig into the class itself, you see a clear collection of object members against which you can work. Note that you can reference the current host via the object $host as so,
Alias: None
On the surface the cmdlet Get-Host could easily be mistaken for a simple .exe like hostname.exe (which returns the local machine name and resides in C:WindowsSystem32 as well as C:WindowsSysWOW64). In PowerShell, a host represents the application running (hosting) the instance of Windows PowerShell. So, for instance, in my console host I can run this cmdlet and get the following results:
Likewise, I can open up an instance of PowerShell ISE v3 and get the following, completely different result:Name :ConsoleHostVersion :3.0InstanceId : 54db2bf5-0964-4660-b9c8-a68fb4331a35UI :System.Management.Automation.Internal.Host.InternalHostUserInterfaceCurrentCulture : en-USCurrentUICulture : en-USPrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxyIsRunspacePushed : FalseRunspace : System.Management.Automation.Runspaces.LocalRunspace
As a quick glance reveals, each instance has its own unique properties. Seeing as PowerShell can be hosted in a wide array of other environments, it is easy to see how this cmdlet is geared mainly for internal usage, as a way to track what is really running the instance of PowerShell. That being said, it quickly explains why the help for Get-Host is so terse. As noted in the help, "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."Name :Windows PowerShellISE HostVersion : 3.0InstanceId : f3a8ceb2-e0e3-4279-bb38-2ab95c56555cUI :System.Management.Automation.Internal.Host.InternalHostUserInterfaceCurrentCulture : en-USCurrentUICulture : en-USPrivateData : Microsoft.PowerShell.Host.ISE.ISEOptionsIsRunspacePushed : FalseRunspace : System.Management.Automation.Runspaces.LocalRunspace
When you start to dig into the class itself, you see a clear collection of object members against which you can work. Note that you can reference the current host via the object $host as so,
In this case, we get a fixed list of items against which we can program. Most of the properties are read-only, hence the {get;} without the corresponding {;set}. Furthermore, hosts, as in this case, truly are one-way objects. Not a lot of access is granted the end user via these routes. Now, if you start working with runspaces in C# and hosts that way, we may have a different conversation. As for generic usage, Get-Host is for all intents and purposes read-only.PS >$host |Get-MemberTypeName: System.Management.Automation.Internal.Host.InternalHostName MemberTypeDefinition---- --------------------EnterNestedPrompt Method voidEnterNestedPrompt()Equals Method boolEquals(System.Objectobj)ExitNestedPrompt Method voidExitNestedPrompt()GetHashCode Method int GetHashCode()GetType Method typeGetType()NotifyBeginApplication Method void NotifyBeginApplication()NotifyEndApplication Method voidNotifyEndApplication()PopRunspace Method voidPopRunspace(),void IHostSupportsInteractiveSession.PopRunspace()PushRunspace Method voidPushRunspace(runspacerunspace),void IHostSupportsInteractiveSession.PushRun...SetShouldExit Method voidSetShouldExit(intexitCode)ToString Method stringToString()CurrentCulture Property cultureinfoCurrentCulture {get;}CurrentUICulture Property cultureinfoCurrentUICulture {get;}InstanceId Property guid InstanceId {get;}IsRunspacePushed Property bool IsRunspacePushed {get;}Name Property string Name{get;}PrivateData Property psobjectPrivateData {get;}Runspace Property runspaceRunspace {get;}UI Property System.Management.Automation.Host.PSHostUserInterfaceUI {get;}Version Property versionVersion {get;}
0 comments:
Post a Comment