[英]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"
}
我希望這會有所幫助。
歡迎使用 StackOverflow:您可以使用多種方式:
https://docs.microsoft.com/en-us/azure/automation/automation-manage-send-joblogs-log-analytics
希望這可以幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.