2016-08-19 63 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中使用了正确的模式。 –

相关问题