首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PowerShell如何确定脚本的执行?

PowerShell如何确定脚本的执行?
EN

Stack Overflow用户
提问于 2014-06-15 08:32:30
回答 1查看 101关注 0票数 0

我想知道如何通过单击Play来确定PowerShell脚本是从PowerShell ISE内部启动的,还是通过预定的任务或其他什么方式启动的?

通过搜索,我找到了变量$MyInvocation.CommandOrigin,这是什么东西可以达到这个目的吗?谢谢你的建议。

我还从这里中找到了以下内容,但这并不能真正决定它是否在ISE中执行:

代码语言:javascript
运行
复制
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)“
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-16 06:06:55

您可以检查是否存在$PSISE变量。它只存在于ISE中,并且是$null或控制台中未定义的。

代码语言:javascript
运行
复制
#In the console this will output False
#In the ISE this will output True
if($PSISE){$true}else{$false}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24227891

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档