How do I start an RDP session from powershell? I'm looking to avoid a custom script because I work at an MSP and end up remoting into machines across various domains in a day and so maintaining a selection of scripts across each is not trivial (unless you have a solution to that for me).
7 Answers
Same as in command line, you can launch the RDP client as so:
mstsc /v:10.10.10.10:3389

- 9,681
- 1
- 29
- 41
-
2It is possible to put the server name as well ;) – DanielV Aug 25 '15 at 09:51
From your desktop, you can start an RDP session pointing to a remote system with this:
Start-Process "$env:windir\system32\mstsc.exe" -ArgumentList "/v:$machinename"
Where $machinename
is the name of the remote system. You will be prompted for credentials.

- 27,574
- 6
- 51
- 97
-
1Thanks, wish PS had a Start-RDPSession $machinename option instead. I think stuff like this demonstrates part of why PS is seeing slow adoption among the sysadmins around me. I wanted to accept both you and Raf. I gave it to Raf because I think his is the one I'll actually remember and I think most will prefer. Yours is the more precise answer though. Thanks! – Josiah Jun 30 '14 at 19:56
-
5Write your own function that does what I wrote, call it that, put it in your `$PROFILE` or make your own module. That sort of extensibility should be *speeding* adoption, not hampering it. – alroc Jun 30 '14 at 20:55
Here it is in function format. As alorc said. Paste this into your $profile
function Start-RDP ($computername)
{
Start-Process "$env:windir\system32\mstsc.exe" -ArgumentList "/v:$computername"
}

- 61
- 1
- 1
Connection settings are stored in .rdp files. There is no need to specify a computer name and list other settings in the code. Connect Hyper-V with settings from .rdp file:
$hyperv = Get-VM -Name "VM-Name"
if($hyperv.State -eq "Running") {
Write-Host "Hyper-V is Running."
Start-Process "$env:windir\system32\mstsc.exe" -ArgumentList "$env:userprofile\Documents\RDP-Name.rdp"
} else {
Write-Host "Hyper-V is Stopped."
Start-VM -Name "VM-Name"
Start-Sleep -Seconds 6
Start-Process "$env:windir\system32\mstsc.exe" -ArgumentList "$env:userprofile\Documents\RDP-Name.rdp"
}
Well, for the beauty of this whole process, create a .vbs file in the same folder that calls your .ps1 file in invisible mode.
Set objShell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set F = FSO.GetFile(Wscript.ScriptFullName)
path = FSO.GetParentFolderName(F)
objShell.Run(CHR(34) & "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe "" -ExecutionPolicy Bypass & ""'" & path & "\Ps1File.ps1'" & CHR(34)), 0, True

- 591
- 3
- 10
Try using this command: mstsc /v:<server>
additionally you can check the following link for further reference:
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/mstsc

- 12,181
- 2
- 31
- 58

- 11
- 3
If you are working with remote hosts in domain, u can use this command:
Enter-PSSession -ComputerName host1 -Credential Username
If not, u should execute some steps.
This link has many other options: http://www.howtogeek.com/117192/how-to-run-powershell-commands-on-remote-computers/

- 1,126
- 1
- 13
- 11