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

标签 azure powershell

我有一个 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/

相关文章:

dataframe - Azure Blob 存储 - 如何读取源字符串 : wasbs://training@dbtrainsouthcentralus. blob.core.windows.net

python - 无法在 azure 函数中导入 pyodbc,但可以在常规 python 文件中导入(在两者中使用相同的 venv)

python - 在 ipython 笔记本上导入 imblearn python 包时出现问题

powershell - PowerShell 是否支持 glob 模式中的否定语法?

powershell - 如何编写包装 sed/perl/etc 命令的 powershell 函数

azure - 将 Application Insights 遥测处理器添加到 Azure Functions

azure - 更新访问 token 生命周期的确切过程

sql-server - Azure 托管标识是否支持本地 MS SQL 数据库?

powershell - 在Powershell中将int转换为char具有意外结果

powershell - 选择并遍历属性