Azure powershell stuff again.  Because it’s all I’ve been doing for 20 hrs straight.  I’m a zombie.  Need sleep….

Warning: no error/exception handling.  This is the economy class. :/

#------------------------------------------------------------------
# Return $TRUE if blob (file) exists in specified location
#------------------------------------------------------------------

function Test-BlobExists {
  param (
    [parameter(Mandatory=$True)] [string] $BlobName,
    [parameter(Mandatory=$True)] [string] $ResourceGroupName,
    [parameter(Mandatory=$True)] [string] $StorageAccountName,
    [parameter(Mandatory=$True)] [string] $ContainerName
  )
  Write-Verbose "[test-blobexists]"
  Write-Verbose "info: BlobName............. $BlobName"
  Write-Verbose "info: ResourceGroupName.... $ResourceGroupName"
  Write-Verbose "info: StorageAccountName... $StorageAccountName"
  Write-Verbose "info: ContainerName........ $ContainerName"

  $StorageKey = (Get-AzureRmStorageAccountKey -ResourceGroupName $ResourceGroupName -Name $StorageAccountName)[0].Value
  $StorageContext = New-AzureStorageContext –StorageAccountName $StorageAccountName -StorageAccountKey $StorageKey
  $(Get-AzureStorageBlob -Context $StorageContext -Container $ContainerName | ?{$_.Name -eq $BlobName})
}
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s