Created
August 22, 2017 04:46
-
-
Save RIKIKU/b88a3894c876b83663319b50866ba5e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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