Search code examples
powershellremote-desktoprdpwinrm

Enter-PSSession unable to remote into a remote desktop


I am trying to remote into another desktop using Powershell's Enter-PSSession to run a script automatically, however, i am not even able to connect to the remote desktop.

Enter-PSSession -Computername 172.16.164.14 -credential $cred

But it says access is denied. This is the error message:

Enter-PSSession : Connecting to remote server 172.16.164.14 failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.

I also tried using:

Invoke-Command -ComputerName 7450-56Z0BP2 -FilePath -C:\user_automation\automate.vbs -credential $cred

where 7450-56Z0BP2 is the hostname, but the error it gave me is:

[7450-56Z0BP2] Connecting to remote server 7450-56Z0BP2 failed with the following error message : WinRM cannot process the request.

I am not sure what could be the cause of me not being able to access the remote computer. I am able to access it via RDP, but I am not able to log in using the powershell script.


Solution

  • PowerShell Remoting is not Remote Desktop, they are both setup differently, use different components and do not really share any commonality.

    Permissions are not linked between the two, just because you can RDP to a computer does not mean you have PSRemoting permissions.

    You use PSRemoting you need to run Enable-PSRemoting on the remote machine. This sets up all the requirements: settings, firewall rules and services. This command needs to be run as a user with Administrator permissions on the remote machine.

    Once this is setup, you will be able to connect using Enter-PSSession / Invoke-Command


    Your code to run a vbscript remotely won't work because the FilePath param is for a PowerShell script. To run a vbscript remotely you need to call cscript:

    Invoke-Command -ComputerName '7450-56Z0BP2' -ScriptBlock { cscript.exe "C:\user_automation\automate.vbs" } -Credential $cred