Recently, while working on one of the Windows Azure migration engagement, we were need to have a simple and portable utility scripts that manipulate on various Windows Azure Storage (WAS) services APIs like “Get all blob metadata details from selected containers”. This is further enabled to perform various manipulations for the business.
There are various options like LINQPad queries, WAPPSCmdlets or Azure Storage Explorer + Fiddler. However, in-terms of considering the computation post to the WAS invocation, repetitiveness of the work and considering the various type of users environment, simple PowerShell script is the option. So, I have decided to write simple PowerShell script using WAS REST API. This does not require any other snap-in or WAS storage client assemblies. (Re-inventing the wheel?!)
One of the main hurdle is creating Authorization header (signing the request). It should contains the following:
- HTTP verb
- all standard HTTP headers, or empty line instead (canonicalized headers)
- the URI for the storage service (canonicalized resource)
A sample string for the signing mentioned below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Read http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx and particularly the section http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx#Constructing_Element for request signing of “Authorization” header.
I have written a simple and dirty PowerShell function for blob metadata access.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
Use [char] 10 for new-line, instead of “`r`n”.
Now, you need to add “Authorization” header while making the request.
1 2 3 4 5 |
|
The complete script is available at my GitHub repo https://github.com/udooz/powerplay/blob/master/README.md.
The real power when accessing REST API from PowerShell is the “XML processing”. I can simply access ListBlob() atom fields like
1
|
|
Happy Coding.