Unable to start PSSession - windows

I am trying to start a new remote session, using Powershell, to a server that is part of a dev domain. There is no trust between these two servers.
[XX-XXX-DB1.didevtest.local] Connecting to remote server
XX-XXX-DB1.didevtest.local 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.
+ CategoryInfo : OpenError: (XX-XXX-DB1.didevtest.local:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionStateBroken
I have enabled WinRM using Enable-PSRemoting and also added my local PC as a trusted system on the remote system using
Set-item wsman:localhost\client\trustedhosts -value.
If I use the IP address of the remote server, I get following error:
New-PSSession : [XXX.XX.X.X] Connecting to remote server
XXX.XX.X.Xfailed with the following error message : The WinRM client
cannot process the request. Default authentication may be used with an
IP address under the following conditions: the transport is HTTPS or
the destination is in the TrustedHosts list, and explicit credentials
are provided. Use winrm.cmd to configure TrustedHosts. Note that
computers in the TrustedHosts list might not be authenticated. For
more information on how to set TrustedHosts run the following command:
winrm help config. For more information, see the
about_Remote_Troubleshooting Help topic. At line:2 char:16
+ ... motesession=New-PSSession -ComputerName "XXX.XX.X.X" -Credential $cre ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession],
PSRemotingTransportException
+ FullyQualifiedErrorId : CannotUseIPAddress,PSSessionOpenFailed Enter-PSSession : Cannot validate argument on parameter 'Session'. The
argument is null or empty. Provide an argument that is not null or
empty, and then try the command again. At line:3 char:26
+ Enter-PSSession -Session $remotesession
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Enter-PSSession], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.EnterPSSessionCommand

Add the remote machine to your TrustedHosts list :
Set-Item WSMan:\localhost\Client\TrustedHosts -Value $ip -force

Related

Enable-PSRemoting command failing in powershell, Azure VM

I tried the Enable-PSRemoting in powershell, Windows 10 Pro, configured in Azure VM.
But the command fails with the following error :
WinRM has been updated to receive requests.
WinRM service type changed successfully.
WinRM service started.
Set-WSManQuickConfig : <f:WSManFault xmlns:f="http://schemas.microsoft.com/wbem/wsman/1/wsmanfault" Code="2150859113"
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="2150859113" Machine="Roshin"><f:Message>WinRM firewall exception will not work since one of the network
connection types on this machine is set to Public. Change the network connection type to either Domain or Private and
try again. </f:Message></f:WSManFault></f:ProviderFault></f:Message></f:WSManFault>
At line:116 char:17
+ Set-WSManQuickConfig -force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Set-WSManQuickConfig], InvalidOperationException
+ FullyQualifiedErrorId : WsManError,Microsoft.WSMan.Management.SetWSManQuickConfigCommand
Can someone help to mitigate this?
I just missed the statment in the error :
WinRM firewall exception will not work since one of the network
connection types on this machine is set to Public. Change the network connection type to either Domain or Private and
try again.
Turning the network to Private from public did the job

Remote Login with Credential gives PSRemotingTransportException

I am just trying to write a script that can remote login with user/pass credentials via Jenkins. I wrote this script that is given below;
$pass = convertto-securestring "SOME_PASSWORD" -asplaintext -force
$mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist "SOME_USERAME",$pass
invoke-command "SOME_COMPUTER_NAME" {get-process} -credential $mycred
After running this script it giving error like;
[SOME_COMPUTER_NAME] Connecting to remote server SOME_COMPUTER_NAME 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.
+ CategoryInfo : OpenError: (SOME_COMPUTER_NAME:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionStateBroken
Before your question and suggestions; just controlled WinRM service local and remote machines, I enabled PSRemoting and Set-Item TrustedHosts on remote machine.

What is the default proxy of Invoke-WebRequest if no proxy is given in the command line

I logged in to my client's server (Windows 2008 Server Standard) and tried to download something in command line. So I use the following command:
Invoke-WebRequest "http://www.example.com/somthing.cab
But then I got the following error message:
Invoke-WebRequest : Authorization Required
Description: Authorization is required for access to this proxy
At line:1 char:1
+ Invoke-WebRequest "http://www.example.com/something.cab"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Moreover I am able to download that file in IE and IE doesn't use any proxy server. None of other command line tool can download via HTTP or HTTPS protocol (FTP is downloadable). There is no environment variable that specifies any proxy server.
What is the default proxy of Invoke-WebRequest and how do I know the proxy server ip address and port number and if it is an NTLM proxy server ?
Thanks

Not able to get instance-id from powershell in EC2 windows machin

I can able to get the instance-id from AWS EC2 windows machine's IE browser using the URL http://169.254.169.254/latest/meta-data/instance-id
In the same machine when I use Powershell command
Invoke-WebRequest http://169.254.169.254/latest/meta-data/instance-id
then I am getting below error
Invoke-WebRequest : Network Error (tcp_error) A communication error occurred: "Operation timed out" The Web Server may be down, too busy, or experiencing other problems preventing it from responding to requests. You may wish to try again at a later time. For assistance, contact your network support team. At line:1 char:1
+ Invoke-WebRequest http://169.254.169.254/latest/meta-data/instance-id
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Note: Invoke-WebRequest http://google.com is working and giving the response from PowerShell cmd.
Please anyone clarify what is this error.
What exactly does this need to do? Download data from the URL? I've never seen such a think before, but I would THINK you could use the System.Web.Uri class to do it, like so:
$var = New-Object System.Web.Uri
$var.Download("http://169.254.169.154/latest/meta-data/instance-id")
Does something like that work?

PowerShell: error executing command using Invoke-Command?

I'm trying to execute the following statement on remoter server:
Invoke-Command -ComputerName server1 -ScriptBlock {Get-Process}
but I get an error message:
[server1] Connecting to remote server failed with the following error message : The client cannot connect to the destination specified in the request. Verify that the serv
ice 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.
+ CategoryInfo : OpenError: (:) [], PSRemotingTransportException
+ FullyQualifiedErrorId : PSSessionStateBroken
What is the reason for this and how to fix it?
There is 2 basical reason:
1) remote computer has not Powershell installed
2) PSremoting is not enabled on remote PC (to enable it read my comment in you answer)

Resources