2

What I need

I want to have an automation runbook that executes commands on a remote VM (the VM is a V2 or "Resource Manager" VM).

I found examples to make that work with Classic VMs but I can't make it work for RM VMs (best I found: https://alexandrebrisebois.wordpress.com/2015/08/14/azure-automation-remote-powershell-and-a-virtual-machine/).

Does anybody have an example of running powershell commands on a remote V2 VM in an automation runbook?

Where I'm stuck currently

I have tried to adjust the 2nd piece of the example code (the part that invokes the command) and I get the following error:

[vm-template] Connecting to remote server vm-template failed with the following error 
message : The WinRM client cannot process the request. If the authentication scheme is 
different from Kerberos, or if the client computer is not joined to a domain, then HTTPS 
transport must be used or the destination machine must be added to the TrustedHosts 
configuration setting. Use winrm.cmd to configure TrustedHosts. Note that computers in the 
TrustedHosts list might not be authenticated. You can get more information about that by
running the following command: winrm help config. For more information, see the 
about_Remote_Troubleshooting Help topic.
+ CategoryInfo          : OpenError: (vm-template:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : ServerNotTrusted,PSSessionStateBroken

My understanding is that since I am not using Kerberos (don't even know what that is) I must use HTTPS. And for that I must do the first half of the example code, which is about importing the certificate (importing where btw since the runbook runs "in azure"?).

I found some pages that explain how to enable HTTPS (Connecting to remote server failed using WinRM from PowerShell) and create the certificate (http://www.jayway.com/2011/11/21/winrm-w-self-signed-certificate-in-4-steps/) but they require some commands to be run on BOTH machines ; I certainly can run commands on my remote VM but I don't understand how I could do it for the client machine which does not really exist since the runbook is running directly in azure.

Any help is greatly appreciated, thanks!

Community
  • 1
  • 1
Nicolas
  • 403
  • 1
  • 6
  • 18
  • Hi, did you successfully run command in ARM VM using runbook? What did you do? I have the same problem and error but cant find any article that will help me. – do_Ob Apr 08 '16 at 07:05
  • Sorry I have given up on runbooks and use my own server to issue commands. – Nicolas Apr 08 '16 at 10:50

1 Answers1

2

Is your network security group configured to open port 5985 (winrm http port) or 5986 if using https? You also might need a public IP, if you plan on using winrm not from Azure automation. You should also be able to use http, so I think the error you're seeing is a generic failure to connect error.

Note: by default, winrm over http and the listener should be set up and listening on your machines. winrm uses message level encryption, so it's not completely in plaintext. You can verify with:

winrm e winrm/config/listener

Which should show you the listener with something like:

Listener [Source="GPO"]
    Address = *
    Transport = HTTP
    Port = 5985
    Hostname
    Enabled = true
    URLPrefix = wsman
    CertificateThumbprint
    ListeningOn = 1.1.1.1

Once you've verified that, I would verify that you can connect to the remote machine using winrm from your own computer. You can easily do that with:

$username = '<admin-user>'
$pass = ConvertTo-SecureString -string '<password>' -AsPlainText -Force
$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $pass
Enter-PSSession -ComputerName <public-IP> -Credential $cred -SessionOption (New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck)

Note that you may have to set your trusted hosts on your own computer to trust the Azure machine to create the winrm session. This can be done with something like: Set-Item WSMan:localhost\Client\TrustedHosts -value * -Force

Note that you should use the Azure VM's actual name for security, not a wildcard.

theadriangreen
  • 2,218
  • 1
  • 14
  • 14
  • Thank you - running that command showed me that `ListeningOn = null` was the problem. I went to the Group Policy `Allow remote server management through WinRM` and put '*' as the IP filter and that fixed it. Initially I had the IP address of my client machine there but I guess I misunderstood that setting. So I assume now to secure this and ensure that only my client machine can allow WinRM it relies on the security group firewall in azure. I will live with running my commands from my client machine instead of the runbook - I find it stays in their queue for too long before being run. Thanks! – Nicolas Jan 09 '16 at 11:07
  • Do you know how secured this is in terms of commands sent to the remote machine? I understand it's using HTTP but you're saying the messages are encrypted? Can I send production commands containing credentials and sensitive values using this setup or should I now work towards using HTTPS instead of HTTP? – Nicolas Jan 09 '16 at 11:14