2012-11-02 127 views

回答

18

你可以这样做:

if ($host.name -eq 'ConsoleHost') # or -notmatch 'ISE' 
{ 
    .. do something .. 
} 
else 
{ 
    .. do something else.. 
} 
3

另一种选择......

Try { 
    Start-Transcript -Path <somepath> | Out-Null 
} 

Catch [System.Management.Automation.PSNotSupportedException] { 
    # The current PowerShell Host doesn't support transcribing 
} 
0

下面是查找的$psISE的所有脑干,而不会产生异常的方法:

if (Test-Path variable:global:psISE) 
{ 
... 
} 
相关问题