【问题标题】:Azure PowerShell - Publish-AzureVMDscConfiguration : throws object not set errorAzure PowerShell - Publish-AzureVMDscConfiguration:抛出对象未设置错误
【发布时间】:2016-08-19 14:59:13
【问题描述】:

我正在为 Azure 中的基础架构创建编写一个自动化脚本,其中包含以下代码:

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

最后一行(Publish-AzureVMDscConfiguration)抛出错误:

Publish-AzureVMDscConfiguration:对象引用未设置为 对象的实例。在 C:\temp\Base.Deploy\ARM.Create.ps1:38 char:5 + 发布-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..

标签: powershell azure azure-blob-storage


【解决方案1】:

@卡尔, 从您的 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

任何结果,请告诉我。

【讨论】:

  • 谢谢 - 它为我指明了正确的方向 :) 我本来打算使用 ARM!我的最终工作代码如下所示 - Publish-AzureRmVMDscConfiguration -ResourceGroupName "MyResourceGroup" -ConfigurationPath "InitialConfig.ps1" -ContainerName "windows-powershell-dsc" -Force -StorageAccountName "MyStorageAccount"
  • 不错。很高兴听到您已解决此问题。这次你在powershell中使用了正确的模式。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-06-12
  • 2011-10-31
  • 2015-04-06
  • 2014-12-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多