Public/Get-Lock.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using namespace Microsoft.Azure.Commands.Profile.Models.Core
using namespace Microsoft.Azure.Storage

function Get-Lock {
    [OutputType([AccessCondition])]
    param ([AzureStorageBlob] $Blob)
    Write-Information "Acquire Lock ..."
    [string] $leaseId = $Null
    try {
        $leaseId =  $blob.ICloudBlob.AcquireLease($Null,$Null)  
    }
    catch {
        Write-Information "Failed to acquire lock." 
        return $Null
    }
    Write-Information "Acquired lock." 
    [AccessCondition] $leaseCondition = [AccessCondition]::GenerateLeaseCondition($leaseId)
    return $leaseCondition
}