Azure PowerShell - Object reference not set to an instance of an object

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 13:09:13

问题


I'm trying to write a PowerShell script to automate EventHub creation using Azure PowerShell. I am following the documentation outlined here and have installed the Azure PowerShell module (v 1.0.3).

I have added the Microsoft ServiceBus library (v3.0) using the following

$scriptPath = Split-Path -parent $PSCommandPath
$dllPath = "$scriptPath\..\..\packages\WindowsAzure.ServiceBus.3.1.2\lib\net45-full\Microsoft.ServiceBus.dll"
Add-Type -Path $dllPath

But as soon as I try and use the Get-AzureSBNamespace command, e.g.

$CurrentNamespace = Get-AzureSBNamespace -Name $Namespace

I get the following error

Get-AzureSBNamespace : Object reference not set to an instance of an object.

the same is true of New-AzureSBNamespace. I have also tried logging into Azure within the same session using Login-AzureRmAccount, but get the same object null reference exception.

Is this a bug, or am i missing something not outlined in the documentation?


回答1:


This is because it uses the Service Management API and not the Resource Manager API. For me I ran:

Add-AzureAccount

And then Get-AzureSBNamespace and other SB cmdlets started working just fine.




回答2:


If you can use PS 5.0 give this a try: msdn



来源:https://stackoverflow.com/questions/34980580/azure-powershell-object-reference-not-set-to-an-instance-of-an-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!