Wednesday, October 12, 2016

Powershell Script to RDP

<#  
.SYNOPSIS  
Script to connect multiple RDP sessions with single username/password

.FILE NAME

Connect.ps1
#>

$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$CredPath = $scriptDir + "\securestring.txt"
$IPPath = $scriptDir + "\IP.txt"

$ComputerName = Get-Content $IPPath
#"IP's are" + $ComputerName

$Credential = Get-Content $CredPath
#"Credentials given are" + $Credential

try
{  

      $ComputerName | ForEach-Object {
      $User = $Credential.Split("#")[0]
      $Password = $Credential.Split("#")[1]
     
      cmdkey.exe /generic:TERMSRV/$_ /user:$User /pass:$Password
      mstsc.exe /v:$_
      #cmdkey.exe /delete:$_
    }

}

catch
{
$originalException = $_.Exception
    "Error: " + $originalException.Message
Exit 1
}

No comments:

Post a Comment