2016-08-19 37 views
0

我寫的基礎設施建立在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對象。任何想法可能造成這種情況?

+0

很難說爲什麼會失敗。 InitialConfig.ps1可能不正確。你能在這裏發表劇本嗎?將有助於更好地診斷此問題。 –

+0

嗨@ 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

回答

0

@Carl, 從您的PowerShell代碼和錯誤消息看來,您在PowerShell中使用了ARM模式。但是,您的代碼應該使用ASM模式。我建議你可以使用Switch-AzureMode來切換你的PowerShell模式,然後再次運行你的代碼。請參考這個博客來檢查他們的差異(https://blogs.msdn.microsoft.com/powershell/2015/07/20/introducing-azure-resource-manager-cmdlets-for-azure-powershell-dsc-extension/)。像這樣

PS C:\> Switch-AzureMode -Name AzureResourceManager 
PS C:\>Switch-AzureMode -Name AzureServiceManagement 

任何結果,請讓我知道。

+0

感謝您的支持 - 它指向我在正確的方向:)我本來打算使用ARM!我的最終工作代碼如下所示:'發佈 - AzureRmVMDscConfiguration -ResourceGroupName「MyResourceGroup」-ConfigurationPath「InitialConfig.ps1」-ContainerName「windows-powershell-dsc」-Force -StorageAccountName「MyStorageAccount」' – Carl

+0

很好。很高興聽到你已經解決了這個問題。這段時間你在PowerShell中使用了正確的模式。 –

相關問題