问题
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