0

I am trying following script to copy a text file from my local machine(Windows 10) to Virtual Machine(VMWare Workstation Player, OS: Windows Server 2016)

$targetComputerName = "192.168.0.103"
$Session = New-PSSession $targetComputerName -Credential 'Administrator'
$DestinationPath = "C:\Users\Administrator\Downloads"
$Source = 'D:\Test.txt'

Copy-Item -Path $Source -ToSession $Session -Destination $DestinationPath
$Session | Remove-PSSession

It gives below error:

New-PSSession : [192.168.0.103] Connecting to remote server 192.168.0.103 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 C:\Users\DELL\Desktop\Untitled1.ps1:2 char:12
+ $Session = New-PSSession $targetComputerName -Credential 'Administrat ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
    + FullyQualifiedErrorId : ServerNotTrusted,PSSessionOpenFailed
Copy-Item : Cannot validate argument on parameter 'ToSession'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command 
again.
At C:\Users\DELL\Desktop\Untitled1.ps1:6 char:36
+ Copy-Item -Path $Source -ToSession $Session -Destination $Destination ...
+                                    ~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Copy-Item], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.CopyItemCommand

N.B: I checked Winrm Service is running on both source and destination, and I can ping destination from source

BlackCat
  • 1,932
  • 3
  • 19
  • 47
  • 1
    By default you can't setup a PSSession to an IP Address unless its in your trusted hosts file. This [link](https://stackoverflow.com/questions/6587426/powershell-remoting-with-ip-address-as-target) has a good write up and a solution for adding to the trusted hosts file – Jonathan Waring Aug 03 '21 at 08:14
  • Thanks @JonathanWaring, It solved the issue! – BlackCat Aug 04 '21 at 11:44

0 Answers0