PowerShell: error executing command using Invoke-Command? - windows

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)

Related

The WinRM client received an HTTP server error status (500)

I am are trying to run a Powershell script from one Windows VM and accessing another Windows VM.
But I am getting the following error. I have verified almost all the forums and made essential configurations but no luck. Does anyone have any idea how to resolve this error ?
##[error][ABC.domain.com] Connecting to remote server
ABC.domain.com failed with the following error message : The WinRM
client received an HTTP server error status (500), but the remote service did
not include any other information about the cause of the failure. For more
information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (ABC.domain.com:String) [
], PSRemotingTransportException
+ FullyQualifiedErrorId : WinRMHttpError,PSSessionStateBroken

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

New-Cluster Installing windows failover cluster remotely

I'm working on a script which will install the windows failover cluster from a remote server
Remote server is hosting windows server 2016.
Cluster contains 2 Nodes Node1 and Node 2 of Windows server 2019
I ran below cmdlet from the remote server and when the node OS was Win 2016 then it created the failover cluster fine without any error, but when the node OS was Windows Server 2019 and the remote server from where I'm running the cmdlet OS is 2016 then I get below error
New-Cluster -Name "newcluster" -Node "win201906","win201905" -StaticAddress "10.0.3.22"
The clustered role was not successfully created. For more information view the report file below.
Report file location: C:\windows\cluster\Reports\Create Cluster Wizard winclus2021 on 2020.08.06 At 19.32.37.htm
New-Cluster : An error occurred while performing the operation.
An error occurred while creating the cluster 'winclus2021'.
An error occurred creating cluster 'winclus2021'.
The parameter is incorrect
file containing the error is generic
As an alternative I thought of running the new-cluster command on the node itself using invoke-command but it gives the error message
Invoke-Command -ComputerName Servername {
New-Cluster -Name $using:Clustername -Node $using:Clusternodes -StaticAddress $using:Clusip
}
There was an error adding node 'win201906' to the cluster
You do not have administrative privileges on the server 'win201906.constosonet.com'.
Attempted to perform an unauthorized operation.
At line:2 char:9
+ Invoke-Command -ComputerName $Reports[0].Servername {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (:) [New-Cluster], ClusterCmdletException
+ FullyQualifiedErrorId : UnauthorizedAccess,Microsoft.FailoverClusters.PowerShell.NewClusterCommand
+ PSComputerName : win201905
Above permission error incorrect as I'm running the cmdlet using domain joined account which is local admin on both the nodes. And I've logged in with that same account on that remote server.
Can you please suggest a better way of creating cluster from a remote server? as both of the above method seems to be difficult to achieve

Unable to start PSSession

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

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.

Resources