title: How to run Azure PowerShell cmd from cloud service
body: <p>I've developed a web role to manage Azure VM's that is working locally but NOT when it's deployed in a Cloud Service. </p>
  
  <p>I have executed the cmd that is in the web role in PowerShell through an RDP connection to the Cloud Service, so I know PowerShell v3.0 and Azure cmd are working fine.</p>
  
  <p>First steps I had some permissions and certs issues but solved, the problem now is I can't see any error in Event Viewer.</p>
  
  <p>I'm using PowerShell.Create() of System.Automation.dll</p>
  
  <pre><code>string script = "Set-ExecutionPolicy Unrestricted -Force
  script = "Import-Module \"D:\\Program Files (x86)\\Microsoft SDKs\\Windows Azure\\PowerShell\\Azure\" 2 &gt;&gt; C:\errorp.out";
  script = "Set-AzureSubscription –DefaultSubscription \"Test Environment\"";
  script = "Get-AzureVM " + vm
  </code></pre>
  
  <p>I'm trying to get the error in all the commands with "2 >> C:\errorp.out" (actually is in all commands but didn't copy here) but it creates a blank file.</p>
  
  <p>Am I missing any extra configuration to be able to do that?</p>