2012-11-02 9 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 
} 
9

が、これはかなり長い間前に聞くと、すでに答えとしてマークされていた知っているが、もう一つの方法:

function Test-IsISE { 
# try...catch accounts for: 
# Set-StrictMode -Version latest 
    try {  
     return $psISE -ne $null; 
    } 
    catch { 
     return $false; 
    } 
} 

$ psISEはISEで利用可能です:

http://technet.microsoft.com/en-us/library/dd819500.aspx

0

ここでの例外生成せず$psISEのexistance探しの方法です:

if (Test-Path variable:global:psISE) 
{ 
... 
} 
関連する問題