none
Powershell - Check and Creating azure storage table.

    Question

  • Hi, Using powershell, I am trying to check existing azure storage table and if it not exists creating one by using the following methods. Is there any other pattern in powershell for the same  .

    Method 1

    # Get Azure Storage table
    $ErrorActionPreference = "SilentlyContinue" 
    $table = Get-AzureStorageTable –Name $tabName –Context $Ctx
    $ErrorActionPreference = "Stop"
     
    If([string]::IsNullOrEmpty($table.Name))
    {
     New-AzureStorageTable –Name $tabName –Context $Ctx
    }
    $table = Get-AzureStorageTable –Name $tabName –Context $Ctx


    Method 2

    try
    {
      $table = Get-AzureStorageTable –Name $tabName –Context $Ctx
    }catch
    {
      -AzureStorageTable –Name $tabName –Context $Ctx
    }
    $table = Get-AzureStorageTable –Name $tabName –Context $Ctx

    if not, out of the two methods which is the best. Please suggest ?


    Vishnu VG

    Friday, May 27, 2016 4:24 AM

All replies

  • Hi,

    I would suggest option 1. This is how i do it:

        $Ctx = New-AzureStorageContext $StorageAccountName -StorageAccountKey $StorageAccountKey

        $table = Get-AzureStorageTable –Name $TableName -Context $Ctx -ErrorAction Ignore

        if ($table -eq $null)
        {
           $table = New-AzureStorageTable –Name $TableName -Context $Ctx
        }

    Best regards

    Friday, May 27, 2016 8:19 AM