我寫的基礎設施建立在Azure的自動化腳本包含以下代碼:Azure中的PowerShell - 發佈 - AzureVMDscConfiguration:拋出對象未設置錯誤
Azure-LoginAndPickSubscription -azureSubscriptionId $CONFIG_AZURE["SUBSCRIPTIONID"] `
-azureUsername $CONFIG_AZURE["USERNAME"] `
-azureEncryptedPassword $CONFIG_AZURE["PASSWORD"] `
-passwordKeyFilePath "$SCRIPT_DIRECTORY\private.key"
$solutionRoot = Split-Path -Path $SCRIPT_DIRECTORY -Parent
$storContext = (New-AzureStorageContext -StorageAccountName mystorename -StorageAccountKey "mystoragekey")
Publish-AzureVMDscConfiguration "$SCRIPT_DIRECTORY\NewDSC\InitialConfig.ps1" -ContainerName "windows-powershell-dsc" -Force -StorageContext $storContext
最後一行(發佈-AzureVMDscConfiguration)拋出一個錯誤:
Publish-AzureVMDscConfiguration : Object reference not set to an instance of an object. At C:\temp\Base.Deploy\ARM.Create.ps1:38 char:5 + Publish-AzureVMDscConfiguration "$SCRIPT_DIRECTORY\NewDSC\Initia ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Publish-AzureVMDscConfiguration], NullReferenceException + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.Extensions.DSC.PublishAzureVMDscConfigurationCommand
我已經檢查了腳本(InitialConfig.ps1)存在,並填充$ storContext對象。任何想法可能造成這種情況?
很難說爲什麼會失敗。 InitialConfig.ps1可能不正確。你能在這裏發表劇本嗎?將有助於更好地診斷此問題。 –
嗨@ Rena-MSFT,感謝評論 - 我已經運行此與沒有問題在一個不同的服務器上安裝的舊版本的cmdlet(1.1.5) - 所以我猜這可能是與問題服務器上使用的新cmdlet版本(2.0.1)。我也可以在問題服務器上運行'Publish-AzureVMDscConfiguration「$ SCRIPT_DIRECTORY \ NewDSC \ InitialConfig.ps1」-ConfigurationArchivePath「C:\ temp \ dsc \ MyConfig.zip」-Force'。 – Carl