0Day Forums
How do I start remote desktop from PowerShell? - Printable Version

+- 0Day Forums (https://0day.red)
+-- Forum: Coding (https://0day.red/Forum-Coding)
+--- Forum: PowerShell & .ps1 (https://0day.red/Forum-PowerShell-ps1)
+--- Thread: How do I start remote desktop from PowerShell? (/Thread-How-do-I-start-remote-desktop-from-PowerShell)



How do I start remote desktop from PowerShell? - multigap601849 - 07-21-2023

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).




RE: How do I start remote desktop from PowerShell? - Proregelating443 - 07-21-2023

Same as in command line, you can launch the RDP client as so:

mstsc /v:10.10.10.10:3389


RE: How do I start remote desktop from PowerShell? - tun707824 - 07-21-2023

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.


RE: How do I start remote desktop from PowerShell? - uella89 - 07-21-2023

at the console prompt type:

mstsc /v:SERVERNAME


RE: How do I start remote desktop from PowerShell? - shorteners185868 - 07-21-2023

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:

[To see links please register here]




RE: How do I start remote desktop from PowerShell? - sautes933097 - 07-21-2023

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"
}


RE: How do I start remote desktop from PowerShell? - susannackxcfvbu - 07-21-2023

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



RE: How do I start remote desktop from PowerShell? - shivdarsankglbvq - 07-21-2023

Try using this command: `mstsc /v:<server>`

additionally you can check the following link for further reference:

[To see links please register here]