我有一个 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"
}
我希望这能有所帮助。
关于azure - 如何检查 powershell 脚本是否正在 Azure 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58577450/