This is a simple test to determine if a .ps1 script is being executed via PShell or PowerShell 5.1
Joe
Code:
$IsPshell = $true
try {
$null = [TakeCommand.PowerShellHost]::ExpandValue('%_cwd')
}
catch {
$IsPshell = $false
}
if ($IsPshell) {
# PSHELL-only callbacks
$cwd = [TakeCommand.PowerShellHost]::ExpandValue('%_cwd')
Write-Host "PSHELL cwd: $cwd"
} else {
Write-Host "Running under PowerShell 5.1"
}
Joe





