Certification Test Tool 1.2 for Azure WinRM cannot complete the operation - powershell

I'm currently trying to connect to my Virtual Machine with Windows Server 2012 Datacenter and connect to it via Certification Test Tool 1.2 for Azure. And always getting this error:
Connecting to remote server xyz-vm.westeurope.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.
I guess the tool is using PSRemot so I checked that:
"winrm" is running.
"PS Remoting" is enabled in the firewall.
Port 5985 and 5986 are in the network security group in Azure and at the local VM Firewall allowed.
I tested the connection via Test-WSMan and I got a connection:
screenshot. But the connection with the Certification Test Tool still failed.
Even after turning the Firewall of the VM completely of, it didn't work
Thank you for your Help

Can you please run in cmd on the Virtual Machine netsh winhttp show proxy
If this shows port 8080 could you then run netsh winhttp reset proxy

According to #Shengbao Shui - MSFT
For a existing VM, you also check this blog. You need create a self-certificate and enable https.

Related

powershell on target machine causes "PSSession could not be created for Machine:'XXX:5986"

I try to use release pipeline and setup a task "run powershell on target machines"
And here are the error messages:
##[error]Unable to create pssession. Error: 'Connecting to remote server XXX failed with the following error message : The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig". For more information, see the about_Remote_Troubleshooting Help topic.'
##[error]The remote session query failed for XXX with the following error message: The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig".
##[error]PSSession could not be created for Machine:'XXX:5986'
My VM is on Azure, and I already open PORT 5986\5985 in 'internet' settings.
I found some article talking about "remote management", however, I am not sure how to set this up on my VM.
https://learn.microsoft.com/en-us/windows/win32/winrm/portal
https://learn.microsoft.com/en-us/powershell/scripting/learn/remoting/winrmsecurity?view=powershell-7.2
Maybe I need some setup are needed for the instance which pipelines are running on (agent pools)?
https://developercommunity.visualstudio.com/t/with-powershell-on-target-machines-task-cant-able/635225
Any suggestion is appreciated.
Update-1
The suggestion from #wade-zhou-msft seems not working. But thanks!
Updata-2
change the network setting, no more error.
But the situation still the same ...
In addition, my 'copy file to remote machine' task works well.
Update-3
I find articles talks about "how to remotely run powershell command from Linux"
https://adamtheautomator.com/psremoting-linux/
It shows that some setup is needed. Maybe I need to setup the instance running my CD jobs?
The task "run powershell on target machines" will start a Enter-PSSession session from your agent machine to target VM.
As per the error message, on your target VM, please run winrm quickconfig to configure the service, run winrm set winrm/config/client '#{TrustedHosts="*"}' to trust the host.
If you use the HTTPS, then you need to open port 5986 in the firewall and install a self-signed certificate.
If you create a classic virtual machine from the Azure portal,the virtual machine is already set up for WinRM over HTTPS, with the default port 5986 already opened in the firewall and a self-signed certificate installed on the machine.These virtual machines can be accessed with no further configuration required. Please refer to the task perquisite for the detials.
Or you can use self-hosted agent, with http port 5985 for the task.
I had the same problem and I solved the problem by using azure cli.
The build agent and the VM were added in the same vNet.
az vm run-command invoke -g MyResourceGroup -n MyVm --command-id RunShellScript --scripts 'echo $1 $2' --parameters hello world
https://learn.microsoft.com/en-us/cli/azure/vm/run-command?view=azure-cli-latest#az-vm-run-command-invoke

Executing commands on a remote server via winrm failed

I am trying to remotely manage a windows server which is Azure AD Domain joined. I have activated winrm on both machines. My user has administrator rights and I am working from an elevated prompt. I have even set the Server as trusted host just in case. No matter what I try I keep getting this error message.
Connecting to remote server xxx failed with the following error message: The WinRM client cannot process the request. If the authentication schme 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: (xxx) [], PSRemotingTranportException
FullyQualifiedErrorId: ServerNotTrusted,PSSessionStateBroken
I am connected via VPN to the company network, I can also ping the server. I also successfully opened a telnet to the server on the port winrm uses normally.
What am I missing?

Unable to connect to remote server using Enter-PSSession cmdlet

I am getting below error message when I try to access one of the AWS Cloud Servers through"Enter-PSSession" cmdlet. I have Admin rights on the server and provide the necessary credential as well but still no gain. Please help to resolve or suggest alternate way to remotely access the Server.
------------------Connecting to remote server XYZ.XXXXXX.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.
Make sure that the server behind that name has the proper IP address.
You can do that if you ping the host name, and then ping the turned IP with attribute -a
Ping server.com
Ping -a <IP returned by that hostname>
If the second ping return different hostname, thats were you have problem.
If it does not return any hostname, then it might be behind switch or firewall rule that does not allow reverse lookup.
If everything is good, try to see if the WinRM is working with the following command
Test-WSMan <hostname or an IP>
If that is return the ProductVersion then that machine has WindowsRemote Manager enabled.
If that is not working then you dont have windows remote management enabled on that machine, and of course check the firewall.
But if you dont have an issue here then you better check if you have CredSSP enabled/disabled, but for that you would need to read a bit more, here is a nice article about it :
https://4sysops.com/archives/using-credssp-for-second-hop-powershell-remoting/
And if after all that you still have the issue, make sure you know if you are using Certificates to authenticate, if thats the case it really depend on how your PKI is all set.
Make sure the remote host is reachable over you network .
if reachable over network, make make sure remoting is enabled on the derstination server.
if windows firewall service is not running, start it on the destination server .

PowerShell/winrm cannot connect to server

I'm attempting to setup a remote session in PowerShell to a server but failing to do so and hit a wall in my troubleshooting.
On the server I want to remote to I have done:
* Enable-PSRemoting
* Restarted and winrm quickconfig to confirm
On my client from where I want to connect to servers I'm attempting to add trusted hosts via:
winrm s winrm/config/client '#{TrustedHosts="servername"}'
This fails with: "WSManFault
Message = The client cannot connect to the destination specified in the request."
Server is standalone and not in a domain, does not have firewall enabled (I can RDP to it just fine.)
Right now I'm simply trying to establish a 1to1 connection to perform some tests so there are no certificates included either so I was under the impression that the HTTPS listener would not be needed if I use trusted hosts?
"Did you enable WinRM on client as well? – PetSerAl "
This was the issue, the client trying to manage the server was not configured with WinRM.
Works well with winrm quickconfig and then say no to setting up a listener!

Configure and listen successfully using WinRM in powershell

I'm testing WinRM connection using Command Prompt on my local and remote machine and my question is devided into two parts.
PART I
I tested TCP/IP connectivity by using ping command to ping : IP Address of local computer and remote computer, default gateway and DNS Server and it runs perfectly on both local and remote computer.
But when testing using WinRM commands, I used this command to locate listeners and addresses
winrm e winrm/config/listener
It gives me this output for my local machine
Listener
Address = *
Transport = HTTP
Port = 5985
Hostname
Enabled = true
URLPrefix = wsman
CertificateThumbprint
ListeningOn =<IP Address>,127.0.0.1, ::1,fe80::100:7f:fffe%13,fe80::803:5e43:50ef:c50%11
But the same command when I run on remote machine gives me an output with everything else the same, except
Listener[Source="GPO"]
.
.
.
ListeningOn=null
I want to configure it to make it listen correctly.
PART II
And when I run these commands one by one on my remote machine
winrm id -r:<machine name>
winrm get winrm/config -r:<machine name>
winrm get wmicimv2/Win32_Service?Name = WinRM -r:<machine name>
It gives a WSMan Fault with an error message as :
The client cannot connect to the destination specified in the request. Verify
that the service on the destination is running and is accepting requests.Consult
the logs and documentation for WS-Management service running on the destination,
most commonly IIs or WinRM. If the destination is the WinRM service, run the
following command on the destination to analyse and configure the WinRM service:
"winrm quickconfig".
Whereas, same commands when I run on my local machine run correctly.
winrm id
winrm get winrm/config
winrm get wmicimv2/Win32_Service?Name = WinRM
At most, all the problems I'm facing is on my remote machine.
What is causing this to happen and how can I configure it to listen and connect successfully?
Thank You.
Part II, I am now able to run these on one of my other remote machines with correct output.
I made some changes in this particular remote machine for which I had posted the question and so, it wouldn't run these commands until I fix the part I but besides that if nothing has been altered it will run just like it does on my other remote machines.
I would still appreciate if someone could help me with part I in which I have to get rid of
Listener[Source=GPO]
..
.
ListeningOn=null
when I run the command
winrm e winrm/config/listener
because this is what is causing issues but I'm not sure how to disable/remove Group Policy Settings.
To determine which group policy is configuring your WinRM you can run the following from an administrative command prompt:
gpresult /h result.html & result.html
In the displayed result, locate Windows Components/Windows Remote Management (WinRM)/WinRM Service. The Winning GPO is where you can enable/disable GPO settings. Use GPMC (Group Policy Management Console) to manage the Group Policy.
ListeningOn=null appears when an administrator has incorrectly configured the Group Policy IPv4 filter setting in Allow automatic configuration of listeners usually with an IP or network that does not exist on the affected Server.
To reset IP addresses (ListeningOn), you probably need to re-create the listener (remove the old HTTP listener and create a new one). Please find the example below.
In PowerShell:
Remove-WSManInstance winrm/config/Listener -SelectorSet #{Address="*";Transport="http"}
New-WSManInstance winrm/config/Listener -SelectorSet #{Address="*";Transport="http"}
Here is the syntax for the specific IP address to bind:
New-WSManInstance winrm/config/Listener -SelectorSet #{Address="IP:192.168.100.2";Transport="http"}
In Command Prompt:
winrm delete winrm/config/Listener?Address=*+Transport=HTTP
winrm create winrm/config/Listener?Address=*+Transport=HTTP
Further reading:
Three ways to configure WinRM listeners.
The Windows Remote Manager (WinRM) service does not start.
Related question: Allow PowerShell remoting only from one address.
I had the same issue and found that when the GPO Setting: Allow remote server management through WinRM had an IPv4 filter set to the IP address of my jumphost the winrm e winrm/config/listener command generated the ListeningOn=null issue.
I solved this by setting the Filter to * and sorting the permissions on firewall level instead.
I solved this changing a GPO, exactly as answered Neossian (sorry, no reputation to just add a comment). But "IPv4 filter" must not be empty, nor accepts CIDR notation (that was my huge mistake). As already said by Craneum, uses "*" for listen on any interface or some range of IP addresses your local network devices are connected (as "192.168.0.1-192.168.0.254" or something like that).
DO NOT USE "192.168.0.0/24" notation. Yes, the help section is very clear on that, yet I used the wrong notation.
The thing is that the IP Range you are entering is not the range that has access to the system but defines the IP range that can be used as the WinRM interface by the system. Means you have to specify a range of IP addresses which includes all the client IPs the GPO is affecting.
Ensure that you have a filter (IPv4 and/or IPv6) defined in the "Allow remote server management through WinRM" under [Computer Configuration]/[Policies]/[Administrative Templates]/[Windows Components]/[Windows Remote Management (WinRM)]/[WinRM Service].
I would suggest a filter of "*" for both IPv4 and IPv6 unless you know what you want to filter.