Product, version and build: 5.6.163
32 or 64 bit version of product: x64
Operating system: Win10 1809
32 or 64 bit OS: x64
I would like to detect if I am running my script under PowerShell Studio. With PowerShell ISE I could check $psISE for null, is there an equivalent for PowerShell Studio? Thanks.
How to detect if a script is running inside PowerShell Studio
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: How to detect if a script is running inside PowerShell Studio
The equivalent of $psISE for PowerShell Studio and PrimalScript is $SAPIENHost. If $SAPIENHost doesn't exist, then it is not running in either of the applications.
Brittney
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: How to detect if a script is running inside PowerShell Studio
Another way to determine what application your script is running under is to use $Host.Name.
If the script is running under PowerShell Studio or PrimalScript, it will return 'PrimalScriptHostImplementation'. If the script is running under the ISE, it will return 'Windows PowerShell ISE Host'.
If the script is running under PowerShell Studio or PrimalScript, it will return 'PrimalScriptHostImplementation'. If the script is running under the ISE, it will return 'Windows PowerShell ISE Host'.
Code: Select all
switch ($Host.Name){
ConsoleHost { }
PrimalScriptHostImplementation { }
'Windows PowerShell ISE Host' { }
}
Brittney
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: How to detect if a script is running inside PowerShell Studio
Perfect, thanks for the quick reply. - Sean