我想知道如何通过单击Play来确定PowerShell脚本是从PowerShell ISE内部启动的,还是通过预定的任务或其他什么方式启动的?
通过搜索,我找到了变量$MyInvocation.CommandOrigin,这是什么东西可以达到这个目的吗?谢谢你的建议。
我还从这里中找到了以下内容,但这并不能真正决定它是否在ISE中执行:
if ($MyInvocation.InvocationName -eq ‘&‘) {
“Called using operator“
} elseif ($MyInvocation.InvocationName -eq ‘.‘) {
“Dot sourced“
} elseif ((Resolve-Path -Path `
$MyInvocation.InvocationName).ProviderPath -eq `
$MyInvocation.MyCommand.Path) {
“Called using path $($MyInvocation.InvocationName)“
}发布于 2014-06-16 06:06:55
您可以检查是否存在$PSISE变量。它只存在于ISE中,并且是$null或控制台中未定义的。
#In the console this will output False
#In the ISE this will output True
if($PSISE){$true}else{$false}https://stackoverflow.com/questions/24227891
复制相似问题