简体   繁体   English

如何在 powershell 脚本中添加 Microsoft.WindowsAzure.Storage 程序集

[英]how to add Microsoft.WindowsAzure.Storage assembly in powershell script

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. New-Object :未找到构造函数。 Cannot find an appropriate constructor for type Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext .找不到类型Microsoft.WindowsAzure.Commands.Storage.AzureStorageContext的合适构造函数。

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.您没有将-ArgumentList参数传递给New-Object ,因此在尝试实例化指定类型时,它将寻找不带参数的构造函数。 The parameterless constructor of the AzureStorageContext class is protected , not public , though... AzureStorageContext class的无参数构造函数是protected ,不是public ,虽然......

 protected AzureStorageContext ();

...so New-Object will not be able to invoke it. ...所以New-Object将无法调用它。

That same Microsoft.WindowsAzure.Storage.dll assembly is used by theAzure.Storage package . Azure.Storage package使用相同的Microsoft.WindowsAzure.Storage.dll程序集。 Upon installing that...在安装那个...

Install-Module -Name Azure.Storage

...you can invoke the New-AzureStorageContext cmdlet to create AzureStorageContext instances... ...您可以调用New-AzureStorageContext cmdlet来创建AzureStorageContext实例...

$AzStorObject = New-AzureStorageContext # Additional parameters needed

Otherwise, there is a public constructor of the AzureStorageContext class...否则,有AzureStorageContext class 的public构造函数...

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

...that you could use if you pass a CloudStorageAccount instance... ...如果您传递CloudStorageAccount实例,您可以使用它...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当包含“ Microsoft.WindowsAzure.Storage”时,C#的Powershell代码不起作用 - Powershell code from C# doesn't work when “Microsoft.WindowsAzure.Storage” is included Azure文件-如何获取Microsoft.WindowsAzure.Commands.Storage.File.dll? - Azure Files - How to obtain Microsoft.WindowsAzure.Commands.Storage.File.dll? Powershell脚本中的引用程序集 - reference assembly in Powershell script 如何使用Powershell在Microsoft Azure中获取存储帐户的使用情况 - How to get the usage for an storage account in Microsoft azure using powershell Get-AzStorageBlob:容器名称“Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageContainer”无效 - Get-AzStorageBlob: Container name 'Microsoft.WindowsAzure.Commands.Common.Storage.ResourceModel.AzureStorageContainer' is invalid 将兑换程序集添加到PowerShell脚本 - Adding Redemption assembly to PowerShell script Powershell脚本参数和相关程序集 - Powershell script parameter and dependant assembly 如何在PowerShell脚本中替换程序集版本的第三个位置 - How to replace third position of assembly version in the PowerShell script 无法将pssnapin microsoft.exchange.management.powershell.admin添加到Powershell Studio脚本 - Unable to add-pssnapin microsoft.exchange.management.powershell.admin to powershell studio script 安装Microsoft 2010的Powershell脚本 - Powershell Script to Install Microsoft 2010
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM