使用powershell从Azure存储下载blob->;LoaderException

使用powershell从Azure存储下载blob->;LoaderException,powershell,azure,azure-storage,Powershell,Azure,Azure Storage,我在Azure启动任务中使用powershell从blobstorage下载blob。我今天通过NuGet将Microsoft.WindowsAzure.Storage library从3.0.3.0更新为4.0.1.0 在库更新文件仍正确下载后,但我在命令窗口中收到相同类型的警告: '无法加载一个或多个请求的类型。有关详细信息,请检索LoaderExceptions属性。“ function download_from_storage ($container, $blob, $connecti

我在Azure启动任务中使用powershell从blobstorage下载blob。我今天通过NuGet将Microsoft.WindowsAzure.Storage library从3.0.3.0更新为4.0.1.0

在库更新文件仍正确下载后,但我在命令窗口中收到相同类型的警告:

'无法加载一个或多个请求的类型。有关详细信息,请检索LoaderExceptions属性。“

function download_from_storage ($container, $blob, $connection, $destination) {
    Add-Type -Path ((Get-Location).Path + '\Microsoft.WindowsAzure.Storage.dll')
    $storageAccount = [Microsoft.WindowsAzure.Storage.CloudStorageAccount]::Parse($connection)
    $blobClient = New-Object Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient($storageAccount.BlobEndpoint, $storageAccount.Credentials)   
    $container = $blobClient.GetContainerReference($container)
    $remoteBlob = $container.GetBlockBlobReference($blob)
    $remoteBlob.DownloadToFile($destination + "\" + $blob, [System.IO.FileMode]::OpenOrCreate)
}

$connection_string = 'DefaultEndpointsProtocol=https;AccountName=<AcountName>;AccountKey=<Accountkey>'

# JRE
$jre = 'jre-7u60-windows-x64.exe'
$node = 'node-v0.10.29-x64.msi'
download_from_storage 'java-runtime' $jre $connection_string (Get-Location).Path
download_from_storage 'nodejs' $node $connection_string (Get-Location).Path
从存储中下载函数($container、$blob、$connection、$destination){
添加类型-Path((获取位置).Path+'\Microsoft.WindowsAzure.Storage.dll')
$storageAccount=[Microsoft.WindowsAzure.Storage.CloudStorageAccount]::解析($connection)
$blobClient=新对象Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient($storageAccount.BlobEndpoint,$storageAccount.Credentials)
$container=$blobClient.GetContainerReference($container)
$remoteBlob=$container.GetBlockBlobReference($blob)
$remoteBlob.DownloadToFile($destination+“\”+$blob[System.IO.FileMode]::OpenOrCreate)
}
$connection_string='DefaultEndpointsProtocol=https;AccountName=;AccountKey=
#JRE
$jre='jre-7u60-windows-x64.exe'
$node='node-v0.10.29-x64.msi'
从存储“java运行时”$jre$connection\u字符串(获取位置)下载\u
从存储“nodejs”$node$connection\u字符串(获取位置)下载\u。路径

由于它仍在工作,我不知道为什么首先会出现此消息。

这并不是对您问题的确切回答,但这里有一种更简单的从blob存储下载文件的方法:

$dlPath = "C:\temp\"
$container = "BlobContainer"
Set-AzureSubscription "NameOfYourSubscription" -CurrentStorageAccount "storageAccountName"
Get-AzureStorageContainer $container | Get-AzureStorageBlob | 
    Get-AzureStorageBlobContent -Destination $container 

您可以通过在启动任务中安装Azure PowerShell本身,然后执行下载Azure blob cmdlet来实现这一点。以下是步骤

自动安装Azure PowerShell

  • 创建新服务项目(新AzureServiceProject)
  • 执行添加AzureWebRole
  • 将cscfg更改为使用osFamily=3(使用与Azure PS兼容的新PS版本)
  • 在WebRole1\bin目录下复制Azure PowerShell MSI
  • 编辑WebRole1\startup.cmd以包括此行msiexec/i AzurePowerShell.msi/quiet
正在验证Azure PowerShell以使其能够执行cmdlet(如果您只想使用存储cmdlet,则可以忽略此步骤,并在执行Get-AzureStorageBlobContent cmdlet时传递存储密钥/名称)

  • 复制WebRole1\bin文件夹中的最新发布设置文件(myPublishSettings.publishsettings)
  • 编辑WebRole1\startup.cmd,使其包含在添加到以下命令之前的行之后:PowerShell.exe–命令“导入AzurePublishSettingsFile.\myPublishSettings.publishsettings)

在新的WorkerRole实例中没有azure powershell。因此,我使用了Add-Type cmdlet。但如果azure powershell可用,您是对的,这将更简单。