title: Running Azure PowerShell commands from a webjob
body: <p><strong>Update</strong>: I used Azure Automation per BenV's suggestion below and it worked! More info can be found <a href="https://azure.microsoft.com/en-us/documentation/articles/automation-first-runbook-textual-powershell/" rel="nofollow">here</a>. </p>
  
  <hr>
  
  <p>I have a PowerShell script that needs to run a few Azure commands like <code>New-AzureStorageContext</code>, <code>Get-AzureStorageContainer</code>, <code>Set-AzureStorageBlobContent</code>, etc. I'd like to run the script as a webjob. </p>
  
  <p>When I run this script as a webjob I receive errors below on the Azure commands. Other PS commands run successfully from the webjob. </p>
  
  <p>I searched StackOverflow and couldn't find posts for these errors generated when Azure commands are run from a webjob. Somewhat related posts mentioned to use <code>Import-Module</code> which is similar to the advice given below. </p>
  
  <p>An older MSDN blogpost suggested adding “Import-Module Azure.ps1” in the PS script and include Azure.ps1 inside the webjob zip file. (It's really Azure.psd1 from my local C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure). Separately, I tried Import-Module with Azure.psd1 then Azure.ps1 thinking the errors might be related to the file extension, but it wasn't. </p>
  
  <p>My webjob .zip file only has my .CMD file, GetLinks.ps1 and Azure.ps1. </p>
  
  <p>My .CMD file launches my PS script with: PowerShell.exe -ExecutionPolicy RemoteSigned -File GetLinks.ps1 </p>
  
  <p>At the top of this .ps1 file I have: "Import-Module .\Azure.ps1". This runs successfully since I see "INFO" statements in my WebJob run log. </p>
  
  <p>Next my PS script tries to run the Azure PS commands and I still get the same errors like the one example error below. </p>
  
  <hr>
  
  <pre><code>New-AzureStorageContext : The term 'New-AzureStorageContext' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
  At D:\local\Temp\jobs\triggered\getlinks2\b2025qk5.ddj\GetLinks.ps1:75 char:19
  + $storageContext = New-AzureStorageContext -StorageAccountName $storageAccountNam ...
  +  ~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo          : ObjectNotFound: (New-AzureStorageContext:String) [], CommandNotFoundException
  </code></pre>
  
  <h2>    + FullyQualifiedErrorId : CommandNotFoundException</h2>