title: How to handle Azure Storage TableOperation errors in PowerShell?
body: <p>Once in a while I get the following error when I try to insert data in Azure table storage.</p>
  
  <pre><code>Exception calling "Execute" with "1" argument(s): "The remote server returned an error: (409) Conflict."
  </code></pre>
  
  <p>Theoretically this could happen when I insert data with a partition key and row key that already exists.</p>
  
  <p>Because I use ticks (one tick is one ten-millionth of a second) for both partition key and row key I don't think this should be the case. Example below.</p>
  
  <p>But anyway, how can I prevent the exception on <code>CloudTable.Execute</code>? Because I have set <code>$ErrorActionPreference = "Stop"</code> it will stop my install script. I don't think I can use <code>-ErrorAction Ignore</code>?</p>
  
  <pre><code>function Corax-Create-Table($tablename)
  {
      $context = New-AzureStorageContext -StorageAccountName $g_storage_account_name -StorageAccountKey $g_storage_account_key
      $table = Get-AzureStorageTable $tablename -Context $context
      if ($table -eq $null)
      {
          New-AzureStorageTable $tablename -Context $context
      }
      return $table
  }
  
  function Corax-Storage-Insert-Message($table, [String]$partitionKey, [String]$rowKey, [String]$category, [String]$level, [String]$message)
  {
      $entity = New-Object "Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity" $partitionKey, $rowKey
      $entity.Properties.Add("Category", $category)
      $entity.Properties.Add("Level", $level)
      $entity.Properties.Add("Message", $message)
      $result = $table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation]::Insert($entity))
  }
  
  $session = $(Get-Date).Ticks
  
  $t = Corax-Create-Table('test')
  Corax-Storage-Insert-Message $t $session $(Get-Date).Ticks "Database" "Progress" "Database table 1 is updated"
  Corax-Storage-Insert-Message $t $session $(Get-Date).Ticks "Database" "Progress" "Database table 2 is updated"
  Corax-Storage-Insert-Message $t $session $(Get-Date).Ticks "Database" "Progress" "Database table 3 is updated"
  Corax-Storage-Insert-Message $t $session $(Get-Date).Ticks "Database" "Progress" "Database table 4 is updated"
  Corax-Storage-Insert-Message $t $session $(Get-Date).Ticks "Database" "Progress" "Database table 5 is updated"
  </code></pre>