使用PowerShell从Azure存储中下载blob - > LoaderException

时间:2014-06-19 08:23:50

标签: powershell azure azure-storage

我使用powershell从Azure启动任务中的blobstorage下载blob。我今天通过NuGet将Microsoft.WindowsAzure.Storage库从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

由于它仍在工作,我只是一无所知,为什么消息首先出现。

2 个答案:

答案 0 :(得分:1)

这不是你问题的答案,但这是一种从blob存储下载文件的简单方法:

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

答案 1 :(得分:0)

您可以通过在启动任务中安装Azure PowerShell本身,然后执行下载Azure blob cmdlet来执行此操作。这里是粗略的步骤

自动安装Azure PowerShell

  • 创建新服务项目(New-AzureServiceProject)
  • 执行Add-AzureWebRole
  • 更改cscfg以使用osFamily = 3(使用与Azure PS兼容的新PS版本)
  • 将Azure PowerShell MSI复制到WebRole1 \ bin目录下
  • 编辑WebRole1 \ startup.cmd以包含此行msiexec / i AzurePowerShell.msi / quiet

对Azure PowerShell进行身份验证,以便它可以执行cmdlet(如果只想使用存储cmdlet,则可以忽略此步骤并在执行Get-AzureStorageBlobContent cmdlet时传递存储密钥/名称)

  • 在WebRole1 \ bin文件夹中复制最新的发布设置文件(myPublishSettings.publishsettings)
  • 编辑WebRole1 \ startup.cmd以在之前添加的行之后包含此行:PowerShell.exe -Command“Import-AzurePublishSettingsFile。\ myPublishSettings.publishsettings”
相关问题