在Azure自动化下使用Runbook中的CreateCloudBlobClient()方法引用Microsoft.WindowsAzure.Storage.dll并创建Cloud Blob客户端

时间:2014-05-30 09:39:20

标签: azure azure-automation

我正在尝试在Azure自动化中创建一个Runbook,它将拍摄VM的快照。我从脚本中心找到了“CreateBlobSnapshot.ps1”。它在Power Shell中运行良好。但是当我尝试在运行本中使用相同的代码时,却抛出了几个异常。

实施例: 在Windows PowerShell工作流程中不支持A.方法调用.....和B.它无法找到Microsoft.WindowsAzure.Storage.dll。我试着写InlineScript而没有运气。请指教。

#Loading Windows Azure Storage Library for .NET.
Write-Verbose-Message"Loading Windows Azure Storage Library from $StorageLibraryPath"
Reflection.Assembly]::LoadFile("$StorageLibraryPath") | Out-Null

$Creds=New-ObjectMicrosoft.WindowsAzure.Storage.Auth.StorageCredentials("$StorageAccountName","$StorageAccountKey")
$CloudStorageAccount=New-ObjectMicrosoft.WindowsAzure.Storage.CloudStorageAccount($creds, $true)
$CloudBlobClient=$CloudStorageAccount.CreateCloudBlobClient()

1 个答案:

答案 0 :(得分:1)

对于问题B,所有Dependent DLL是否也被加载了?试试这个To Load Windows Storage Dll

PM> Install-Package WindowsAzure.Storage 

然后尝试使用以下方法在PowerShell中加载DLL:

PM> Add-Type -Path "<Path where package is present>\Microsoft.WindowsAzure.Storage.dll"