We are attempting to automate a large number of our azure/service maintenance tasks using a combination of Azure Service Bus queues and Azure Worker Roles. In short, the concept is as follows....
- Maintenance task is posted to SB Queue
- Worker role listens for tasks on the SB Queue
- Worker role connects to desired VM/Web Role/Cloud service and executes a remote powershell command
In practice, this works as expected when operating within a development environment, however after the worker role is published, the remote powershell connection fails with the response "Access is denied". The code to establish the connection is as follows...
PSCredential cred = new PSCredential(config.Username, config.PrimaryPassword);
WSManConnectionInfo connection = new WSManConnectionInfo(true, config.PrimaryServer, 5986, "/wsman", "http://schemas.microsoft.com/powershell/Microsoft.PowerShell", cred);
using (Runspace runspace = RunspaceFactory.CreateRunspace(connection))
{
runspace.Open();
using (PowerShell shell = PowerShell.Create())
{
shell.Runspace = runspace;
// DO SOMETHING HERE
shell.Invoke();
}
runspace.Close();
}
Initially, I had suspected that this was a CA certificate issue, however I have since connected to the worker role via RDP and confirmed that the certificates are being deployed correctly. In addition I have also managed to acheive a connection to the target server via a "winrs -r:" command also using the remote desktop connection.
As confirmation, the worker role is also running with elevated permissions.
Any help with this would be much appreciated
Thanks in advance