2012-11-02 16 views

risposta

18

Si può fare:

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

Un'altra alternativa ...

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

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

sai che questo è stato chiesto un po 'di tempo fa, e già segnato come risposta, ma un altro modo:

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

$ psise è disponibile in ISE:

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

0

Ecco un metodo che cerca l'esistenza di $psISE senza eccezioni che generano:

if (Test-Path variable:global:psISE) 
{ 
... 
} 
Problemi correlati