繁体   English   中英

如何检查 powershell 脚本是否在 Azure 中运行

[英]How-to check that powershell script is running in Azure

我有一个 powershell 脚本,我正在本地 PC 上开发并部署到 Azure 上。 该脚本使用凭据,在 PC 和 Azure 中处理方式不同。 因此,我需要可靠地检查脚本是在 PC 上还是在 Azure 上运行。

我找不到任何可以告诉我答案的命令。 我希望你能帮忙。

我知道这很旧,但如果目标是能够在本地运行脚本以进行开发,那么这应该可以工作。

if ($env:computername -ne "<EnterYourComputerNameHere>") {
    # Script is running in Azure
    # use Azure Automation credentials
} else {
    # Script is running locally
    # us Local credential process
}
enter code here

#do the remainder of your work

我在 Azure 中检查了特定的环境变量。 看起来这在这种情况下会更合适:

if ($env:AUTOMATION_ASSET_ACCOUNTID) {
    "Running in Azure Automation"
} else {
    "Running outside of Azure Automation"
}

我希望这会有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM