Hello there,
I am trying to execute some PowerShell code in a remote computer using the following:
$session = New-PSSession -Credential "myDomain\myUserName" -ComputerName "remoteCompName"
$result = Invoke-Command -Session $session -ScriptBlock {
New-Item -type file C:\test10.txt
}I am an admin on the remote box. It is a 2012 R2 VM.
I am prompted to enter my password in a GUI. I do that. It then errors out with:
New-PSSession : One or more computer names are not valid. If you are trying to pass a URI, use the -ConnectionUri parameter, or pass URI objects instead of strings.
Things to know:
- The machine is part of the domain and is running.
- I checked if PS remoting is enabled. It was.
- I checked if WinRM is running. It is.
Here is what I tried:
- I replaced the computer name with the FQDN. Still no luck.
- I removed the credential parameter
- I tried another remote machine (also a VM)
- I tried another source machine, i.e. the machine I am running the command from)
None of the above helped. What is going on here?
There are other questions on TechNet and stackoverflow on executing PowerShell scripts on remote machines of course but none address this error.
Thanks!
-Rohan.