-
Notifications
You must be signed in to change notification settings - Fork 162
/
Get-Blob.ps1
22 lines (19 loc) · 1.11 KB
/
Get-Blob.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function Get-Blob {
param (
[Microsoft.WindowsAzure.Commands.ServiceManagement.Model.IPersistentVM]$VM
)
$ServiceName=$vm.ServiceName
$storageAccount = (Get-AzureSubscription -current).CurrentStorageAccountName
if($storageAccount -eq $null){
throw New-Object -TypeName InvalidOperationException -ArgumentList "The CurrentStorageAccountName has not been set. Use Set-AzureSubscription to set your current storage account"
}
Write-BoxstarterMessage "Getting azure storage key..." -Verbose
$key = Invoke-RetriableScript { (Get-AzureStorageKey -StorageAccountName $args[0]).Primary } $storageAccount
$creds = New-Object Microsoft.WindowsAzure.StorageCredentialsAccountAndKey($storageAccount,$key)
Write-BoxstarterMessage "Getting OS disk..." -Verbose
$vmOSDisk=Invoke-RetriableScript { Get-AzureOSDisk -vm $args[0] } $VM
$blobURI = $vmOSDisk.MediaLink
$blobPath = $BlobUri.LocalPath.Substring(1)
$blobClient = New-Object Microsoft.WindowsAzure.StorageClient.CloudBlobClient("http://$($blobUri.Host)", $creds)
return $blobClient.GetBlobReference($blobPath)
}