0
votes

I am trying to execute remote commands in the azure virtual machine connected with Azure Active Directory domain controller using WINRM HTTP client from Azure Runbook script as workflow module. Here is my code which connect the remote session.

Code:

    $uri- kerberoscluster.eastus2.cloudapp.azure.com (WINRM HTTP port 5985 and WINRM HTTPS port 5986 were enabled)

    $cred- New-Object -typename System.Management.Automation.PSCredential -argumentlist $vmusername, $vmsecurepassword 

New-PSSession -ComputerName $uri -Credential $cred 

I need to execute the remote command into azure virtual machine using runbook script. But Runbook script execution has been suspended with following exception. Same thing is working fine in on-premises network.

The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: [kerberoscluster.eastus2.cloudapp.azure.com] Connecting to remote server kerberoscluster.eastus2.cloudapp.azure.com 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.
https://docs.microsoft.com/en-us/azure/automation/automation-troubleshooting-automation-errors#troubleshoot-common-errors-when-working-with-runbooks

And also I have tried to connect the remote session using WINRM HTTPS client by referring the below link https://blogs.technet.microsoft.com/rohit-minni/2017/01/18/remoting-into-azure-arm-virtual-machines-using-powershell/

Got the below exception:

New-PSSession : [kerberoscluster.eastus2.cloudapp.azure.com] Connecting to remote server
kerberoscluster.eastus2.cloudapp.azure.com failed with the following error message : WinRM cannot complete the
operation. Verify that the specified computer name is valid, that the computer is accessible over the network, and
that a firewall exception for the WinRM service is enabled and allows access from this computer. By default, the WinRM
firewall exception for public profiles limits access to remote computers within the same local subnet. For more
information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:1
+ New-PSSession -ComputerName $uri -Credential $cred -UseSSL -SessionOption $sessi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotin
   gTransportException
    + FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionOpenFailed

Any help would be greatly appreciated.

1

1 Answers

0
votes

Does the Org User Id or the SPN used for running the runbook have required permissions to the Resource group containing the VMs? This error will usually come due to permissions Issue.