Auto Detect PowerShell Azure Runbook (or Local) Runspace

Wanted to share quick code snippet for how to detect if current PS1 host environment is Azure RUNBOOK or LOCAL console like POWERSHELL_ISE or POWERSHELL.EXE. Cheers.

SCREENSHOT

CODE

if ($host.Runspace) {if ($host.Runspace[0].GetType().Name -eq “LocalRunspace”) {$local=$true; “LOCAL”}} else {“RUNBOOK”}

REFERENCE

https://docs.microsoft.com/en-us/powershell/scripting/developer/hosting/windows-powershell-host-quickstart?view=powershell-7.2

Leave a Comment