Is there a way to check if the script is running by PowerShell ISE?
Here's a method that looks for the existance of $psISE
without generating exceptions:
if (Test-Path variable:global:psISE)
{
...
}
You can do:
if ($host.name -eq 'ConsoleHost') # or -notmatch 'ISE'
{
.. do something ..
}
else
{
.. do something else..
}
Know this was asked quite a while ago, and already marked as answered, but one more way:
function Test-IsISE {
# try...catch accounts for:
# Set-StrictMode -Version latest
try {
return $psISE -ne $null;
}
catch {
return $false;
}
}
$psISE is available in ISE:
http://technet.microsoft.com/en-us/library/dd819500.aspx