.netpowershellpowershell-3.0

Is there a way to check if the script is running by PowerShell ISE?


I want to skip the Start-Transcript and Stop-Transcript lines if the PowerShell script is running by PowerShell ISE.

Is this possible? And how can I achieve this?


Solution

  • You can do:

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