how to add Microsoft.WindowsAzure.Storage assembly in powershell script

532 views Asked by At
Add-Type -Path c:\AzureStorageFile\Microsoft.WindowsAzure.Storage.dll

$AzStorObject = New-Object -TypeName Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext

Gives me error

New-Object : A constructor was not found. Cannot find an appropriate constructor for type Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext.

1

There are 1 answers

0
Lance U. Matthews On

You are not passing the -ArgumentList parameter to New-Object, so when attempting to instantiate the specified type it will look for a constructor that takes no parameters. The parameterless constructor of the AzureStorageContext class is protected, not public, though...

protected AzureStorageContext ();

...so New-Object will not be able to invoke it.

That same Microsoft.WindowsAzure.Storage.dll assembly is used by the Azure.Storage package. Upon installing that...

Install-Module -Name Azure.Storage

...you can invoke the New-AzureStorageContext cmdlet to create AzureStorageContext instances...

$AzStorObject = New-AzureStorageContext # Additional parameters needed

Otherwise, there is a public constructor of the AzureStorageContext class...

public AzureStorageContext (Microsoft.WindowsAzure.Storage.CloudStorageAccount account);

...that you could use if you pass a CloudStorageAccount instance...

$AzStorObject = New-Object -TypeName Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext -ArgumentList $myCloudStorageAccount