Skip to content

Instantly share code, notes, and snippets.

@RIKIKU
Created August 22, 2017 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RIKIKU/b88a3894c876b83663319b50866ba5e4 to your computer and use it in GitHub Desktop.
Save RIKIKU/b88a3894c876b83663319b50866ba5e4 to your computer and use it in GitHub Desktop.
<#
.Synopsis
Opens a new RDP connection to a specified computer using the given credentials.
.DESCRIPTION
Give this thing an array of computer names and a credential to connect to them on and it will open up an RDP session and log you into all of them.
This is great for when you have a huge list of computers that you need to remote into.
.EXAMPLE
$cred = get-credential
$ListOfComputerNames = "Server1","Server2","Server3"
$ListOfComputerNames | Connect-RDPComputers -Credential $cred
In this example, I supply a credential object and an array of computer names.
I then pipe the computer names into Connect-RDPComputers and it will open an RDP session for each computer and log me into each of them with the given credential.
#>
function Connect-RDPComputers
{
[CmdletBinding()]
Param
(
[Parameter(
Mandatory=$true,
ValueFromPipeline=$true
)]
[string]
$Computer,
[Parameter(Mandatory=$true)]
[pscredential]
[System.Management.Automation.CredentialAttribute()]
$Credential=$null
)
Begin
{
import-module CredentialManager
}
Process
{
New-StoredCredential -Target $($computer) -UserName $Credential.UserName -SecurePassword $Credential.Password -Type Generic | Out-Null
mstsc.exe /v:$($computer)
}
End
{
$Credential.Password.Dispose()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment