title: How to contruct an Authorization Header for Azure Storage get container property REST API
body: <p>I am trying to use the Azure Storage <a href="https://msdn.microsoft.com/en-us/library/azure/dd179370.aspx" rel="nofollow">Get Container Properties REST API</a>. I follow the "<a href="https://msdn.microsoft.com/en-us/library/azure/dd179428.aspx" rel="nofollow">Authentication for the Azure Storage Services</a>" to construct an Authorization Header for the request. Here is the PowerShell script I use.</p>
  
  <pre><code>$StorageAccount = "&lt;Storage Account Name&gt;"
  $Key = "&lt;Storage Account Key&gt;"
  $resource = "&lt;Container Name&gt;"
  
  $sharedKey = [System.Convert]::FromBase64String($Key)
  $date = [System.DateTime]::UtcNow.ToString("R")
  
  $stringToSign = "GET`n`n`n`n`n`n`n`n`n`n`n`nx-ms-date:$date`nx-ms-version:2009-09-19`n/$StorageAccount/$resource`nrestype:container"
  
  $hasher = New-Object System.Security.Cryptography.HMACSHA256
  $hasher.Key = $sharedKey
  
  $signedSignature = [System.Convert]::ToBase64String($hasher.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($stringToSign)))
  
  $authHeader = "SharedKey ${StorageAccount}:$signedSignature"
  
  $headers = @{"x-ms-date"=$date
               "x-ms-version"="2009-09-19"
               "Authorization"=$authHeader}
  
  $container = Invoke-RestMethod -method GET `
               -Uri "https://$StorageAccount.blob.core.windows.net/$resource?restype=container" `
               -Headers $headers
  </code></pre>
  
  <p>From the above script, I get Authentication failed error. The Authorization header is not correctly formed.</p>
  
  <p>Any idea on how to fix this?</p>