Unable to establish an HTTP or HTTPS remoting session - powershell

I am enabling windows node for ansible. For this I am enabling http and https remote session in windows 7 using below command.
#powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://github.com/ansible/ansible/raw/devel/examples/scripts/ConfigureRemotingForAnsible.ps1'))"
I am getting the below error in office.
Could you please help me on this?
At home in another laptop it is working fine.
+ Throw "Unable to establish an HTTP or HTTPS remoting session."
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (Unable to estab...moting session.:String) [], RuntimeException
+ FullyQualifiedErrorId : Unable to establish an HTTP or HTTPS remoting session.
I tried with below options:
set http_proxy=http://lsl5kor:N%40llapat12#jk-proxy-apac.india.com:8080/
set https_proxy=http://lsl5kor:N%40llapat12#jk-proxy-apac.india.com:8080/
set http_proxy=http://lsl5kor:N#llapat12#jk-proxy-apac.india.com:8080/
set https_proxy=http://lsl5kor:N#llapat12#jk-proxy-apac.india.com:8080/
set HTTP_PROXY=http://lsl5kor:N#llapat12#jk-proxy-apac.india.com:8080/
set HTTPS_PROXY=http://lsl5kor:N#llapat12#jk-proxy-apac.india.com:8080/
set HTTP_PROXY=http://lsl5kor:N%40llapat12#jk-proxy-apac.india.com:8080/
set HTTPS_PROXY=http://lsl5kor:N%40llapat12#jk-proxy-apac.india.com:8080/
i tried with all above details ...stil not working
Update:
Seems, connection created(Logged in). I observed below event log in windows machine
The WinRM service has received an unsecure HTTP connection from hostname.
This is not a secure configuration.
User Action
Set AllowUnencrypted to False in WinRM configuration to ensure packets are encrypted on the wire.
Thanks in advance.

You could be behind a proxy. If so try setting your proxy first:
set http_proxy=IP:Port
set https_proxy=IP:Port
Or you can goto your Control Panel->Internet Options->Connections->LAN Settings->Proxy servers.
All together:
set http_proxy=IP:Port
set https_proxy=IP:Port
#powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://github.com/ansible/ansible/raw/devel/examples/scripts/ConfigureRemotingForAnsible.ps1'))"

Related

Attempting to run Powershell on Remote Computer - Errors

I am wanting to access another windows device on my local network and run powershell commands. In my mind, it would be similar to SSH into a linux box. I would have an open window on my machine, but would be operating within the remote machine so that I can execute composer install or php artisan migrate type commands on the remote machine.
I have followed the instructions from:
https://www.howtogeek.com/117192/how-to-run-powershell-commands-on-remote-computers/
I am attempting to use
Enter-PSSession -ComputerName <RemoteComputerName> -Credential <RemoteUser>
When I run the command, I get a popup with the username populated and asking for a password. I have entered my MS password for the account. (I have changed the password from within Windows to ensure they are synced)
And I get the following error:
Enter-PSSession : Connecting to remote server <REMOTECOMPUTER> 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.
At line:1 char:1
+ Enter-PSSession -ComputerName <REMOTECOMPUTER> -Credential <USER>
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (<REMOTECOMPUTER>:String) [Enter-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : CreateRemoteRunspaceFailed
I can't seem to figure out how to do this. And, maybe more importantly, is there a better way/utility to accomplish my goal? The remote computer is hosting WAMP and I just want to be execute development commands remotely so I can move the RemoteComputer into the basement and not have to spin my chair around to type on it.
TIA

Why do I get a "Get-WindowSize" not implemented error when using the PowerShell call Get-Service on a remote machine?

I have a Windows 10 host machine that connects to a Hyper-V Windows 10 VM hosted on the same box.
I've been following along the Pluralsight PowerShell tutorial.
I'm trying to get the services available on a remote computer.
I can start a session on the remote computer with the following command:
Enter-PSSession -ComputerName Client1 -Credential username
Once the session has started and I am connected, I attempt to call Get-Service to identify the services on the client computer.
[Client1]: PS C:\Users\username\Documents>Get-Service
When I run the above command, I get the following error message:
Remote host method get_WindowSize is not implemented.
+ CategoryInfo : ResourceUnavailable: (:) [out-lineoutput], PSRemotingDataStructureException
+ FullyQualifiedErrorId : System.Management.Automation.Remoting.PSRemotingDataStructureException,Microsoft.PowerShell.Commands.OutLineOutputCommand
I am running the same version of PowerShell on the host and client machines (5.1.18362.145).
I assume that somehow this is an issue on the client machine?
[Client1]: PS C:\Users\username\Documents>Get-Service | out-string
That should work, maybe a bug with PowerShell or new version of Windows 10
Other link : https://social.technet.microsoft.com/Forums/en-US/67142783-2acd-4d54-aef2-8d89d71457c5/powershell-remoting-broken-in-windows-10-1903?forum=winserverTS
"Remote host method get_WindowSize is not implemented."
This happens to all Remoting Sessions started With Powershell_ISE on the Client-Side.
The workaround with Out-String sucks, it destroys the Result-Object of that call.
Best fix so far is either using not ISE or embed your remote Procedure in a Script and call it with Powershell.exe
Really annoying...and not fixed by now.
Workaround Example: Instead of using enter-pssession and then asking for a result of running services, you could use: $YourServices=Invoke-command -ComputerName <computername> -ScriptBlock {get-service}. Then you have all Service-Stats in your Object $YourServices.

Fix "Unable to check the status of the firewall" of `Set-WSManQuickConfig`

Why Enable-PSRemoting/Set-WSManQuickConfig can not "check the status of the firewall" running under Administrator on Windows 2012R2, Azure WebRole? How to fix this?
PS D:\Users\***User> enable-psremoting -force
WinRM is already set up to receive requests on this computer.
Set-WSManQuickConfig : <f:WSManFault xmlns:f="http://schemas.microsoft.com/wbem/wsman/1/wsmanfault" Code="2"
Machine="localhost"><f:Message><f:ProviderFault provider="Config provider"
path="%systemroot%\system32\WsmSvc.dll"><f:WSManFault xmlns:f="http://schemas.microsoft.com/wbem/wsman/1/wsmanfault"
Code="2" Machine="RD***CA2"><f:Message>Unable to check the status of the firewall.
</f:Message></f:WSManFault></f:ProviderFault></f:Message></f:WSManFault>
At line:69 char:17
+ Set-WSManQuickConfig -force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Set-WSManQuickConfig], InvalidOperationException
+ FullyQualifiedErrorId : WsManError,Microsoft.WSMan.Management.SetWSManQuickConfigCommand
OS Name: Microsoft Windows Server 2012 R2 Datacenter. OS Version: 6.3.9600 N/A Build 9600. Powershell: 4.0
PS.
Yes, there are:
Error PSRemoting using Session and CredSSP. No clear solution
Winrm quick config shows error . Rebooting/reimaging the instance does not help.
https://support.microsoft.com/en-us/kb/2697738. Hotfix (2012 year!) is not installed but then it needs installed each deployment?
https://technet.microsoft.com/en-us/library/hh849694.aspx. Has this message but that is for "client versions"
http://terenceluk.blogspot.ru/2012/05/executing-command-winrm-quickconfig.html Restarting firewall does not help
How to enable powershell remoting in Powershell V3?. No "HKLM:\SYSTEM\Policies\Microsoft\Windows Firewall" to change. restarting firewall service does not help.
Update.
Other valuable refs:
http://www.thomasmaurer.ch/2011/01/quick-powershell-remoting-guide/
http://www.davidaiken.com/2011/01/12/enable-powershell-remoting-on-windows-azure/
Get-Help about_Remote_Troubleshooting
In my case running this helped (manually creates the firewall rule):
netsh advfirewall firewall add rule name="Windows Remote Management (HTTP-In)" dir=in action=allow service=any enable=yes profile=any localport=5985 protocol=tcp
Taken from http://www.davidaiken.com/2011/01/12/enable-powershell-remoting-on-windows-azure/
I tried to enable winrm for ansible testing, nothing helped, the rules were in place. Changing the Windows display language from czech to english fixed my problem.

Powershell Invoke-RestMethod "Unable to connect to the remote server"

I write a very simple powershell script to post a json string to server. I have a strange issue when I execute the script.
The server is inside our intranet, the firewall is disable for all intranet server.
I tried to execute the script in different places:
Powershell window in my own computer (windows 7, powershel 5)
Powershell ISE in my computer
start powershell.exe in a command prompt in my own computer
start powershell.exe in a third party command prompt application in my own computer
Powershell window in a citrix seesion (windows 10, powershel 5)
start powershell.exe in a command prompt in a citrix seesion
I checked all of 6 places have ExecutionPolicy "RemoteSigned",
But, I can only successfully execute the script in last 3 places,
In first 3 place, I get an error
Invoke-RestMethod : Unable to connect to the remote server
At F:\Temp\test.ps1:46 char:9
+ $resp = Invoke-RestMethod -Method POST -Body $result ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-RestMethod],
WebException
+ FullyQualifiedErrorId : System.Net.WebException,Microsoft.PowerShell.Com
mands.InvokeRestMethodCommand
Besides, I also tried Invoke-WebRequest, I got same error message.
Any idea why this is happen? What should I do with it?
I solved same problem by disabling / commenting out proxy settings in the machine.config file which I enabled to intercept network calls from my .Net application in Fiddler.
Please note that you need to restart your computer after you make change in machine.config file. And also make sure you run editor as Administrator to edit config file.
Path:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config
Configuration Element:
configuration -> system.net -> defaultProxy
I had similar issue few days back and I resolved it by applying the proxy settings in the "Invoke-WebRequest" call.
Something like this;
Invoke-WebRequest -URI $url -Proxy 'http://10.10.7.11:80' -ProxyCredential $creds

How to Specify the Password to repadmin.exe via Remote PowerShell Session

I have some issues with repadmin.exe utility
I have the following setup:
Windows Server 2012R2 with ADDS installed running inside of VMWare VM
Windows 8.1 Pro (host for VMware, my home desktop). My host is NOT a part of the domain
I do the following:
Open PowerShell ISE on my Windows 8.1 and establish remote connection to my DC (PowerShell ISE -> File -> New Remote PowerShell Tab)
Once I`m connected remotely to DC I run the following command
repadmin.exe /syncall
and get the following error:
CALLBACK MESSAGE: Error contacting server ad864315-1f78-4266-a7c2-2d6f9cde2f15._msdcs.arvo.local (network error): 5 (0x5):
Access is denied.
CALLBACK MESSAGE: Error contacting server a5904e4b-dff2-4b75-b856-45593a48d84e._msdcs.arvo.local (network error): 5 (0x5):
Access is denied.
SyncAll exited with fatal Win32 error: 8440 (0x20f8):
The naming context specified for this replication operation is invalid.
I found here http://technet.microsoft.com/de-de/library/cc811552%28v=ws.10%29.aspx that is is possible to specify username and password for repadmin using /u: and /pw: keys. Besides it is possible to pass the password using 2 methods - either specify it explicitly in command line or put * (asterisks) and I will be prompted to enter the password. The second option is more preferable.
So I can do ether this way (specify the password in command line):
repadmin.exe /u:domain_name\user_name /pw:p#ssw0rd /syncall
or use asterisks and enter password after this command:
repadmin.exe /u:domain_name\user_name /pw:* /syncall
Asterisks works locally in PowerShell on the server, but if I run it using Remote PowerShell Session, I get the following error:
repadmin : Password: Failed to query the console mode.
+ CategoryInfo : NotSpecified: (Password: Faile...e console mode.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Is there any workaround? I would not specify the password clearly in command line as it is not secure.
Thanks!
You might try something like this inside the remote PowerShell session:
$MyCreds = Get-Credential
Start-Process -FilePath repadmin.exe -ArgumentList "/syncall" -Credential $MyCreds
That way, you could leverage the security of PowerShell's credential management and just run the process under an account that has access to perform the replication.