I am trying to create an object of type Microsoft.ServiceBus.Messaging.SharedAccessAuthorizationRule in Powershell. The Constructor takes a key and list of Rules. Below is the code. I get the following error. Error:
New-Object : Cannot find an overload for "SharedAccessAuthorizationRule" and the argument count: "2".
At line:39 char:10
$Rule = New-Object -TypeName Microsoft.ServiceBus.Messaging.SharedAccessAuthori ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : InvalidOperation: (:) [New-Object], MethodException
FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
Script:
cls
Add-Type -Path "C:{Your Service Bus dll location}Microsoft.ServiceBus.dll"
Add-Type -Path "C:{Your WindowsAzure.configuration Location}Microsoft.WindowsAzure.Configuration.dll"
$AccessRights = New-Object -TypeName 'System.Collections.Generic.List[Microsoft.ServiceBus.Messaging.AccessRights]' ;
$CanManage = $true;
$CanListen = $true;
$CanSend = $true;
if ($CanManage)
{
$AccessRights = $AccessRights + [Microsoft.ServiceBus.Messaging.AccessRights]::Manage;
}
if ($CanListen)
{
$AccessRights = $AccessRights + [Microsoft.ServiceBus.Messaging.AccessRights]::Listen;
}
if ($CanSend)
{
$AccessRights = $AccessRights + [Microsoft.ServiceBus.Messaging.AccessRights]::Send;
}
$Rule = New-Object -TypeName Microsoft.ServiceBus.Messaging.SharedAccessAuthorizationRule -ArgumentList "2", $AccessRights;
See Question&Answers more detail:os