Advertisement
Guest User

Untitled

a guest
Sep 4th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #Script for RDP/MSTSC auto login
  2. function connect {
  3. param ([Parameter(Mandatory = $true)]
  4. [string[]]$Computer )
  5. $User = "administrator"
  6.  
  7. if (-not (Test-Path .\Pass.txt)) {
  8. read-host -assecurestring "Enter Password" | convertfrom-securestring | out-file .\Pass.txt
  9. }
  10. $password = Get-Content .\pass.txt | convertto-securestring
  11. $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $User, $password
  12. $pass = $cred.GetNetworkCredential().Password
  13. $ProcessInfo = New-Object System.Diagnostics.ProcessStartInfo
  14. $Process = New-Object System.Diagnostics.Process
  15. $ProcessInfo.FileName = "$($env:SystemRoot)\system32\cmdkey.exe"
  16. $ProcessInfo.Arguments = " /generic:TERMSRV/$Computer /user:$User /pass:$Pass"
  17. $Process.StartInfo = $ProcessInfo
  18. $Process.Start()
  19.  
  20. $ProcessInfo.FileName = "$($env:SystemRoot)\system32\mstsc.exe"
  21. $ProcessInfo.Arguments = " /v $Computer"
  22. $Process.StartInfo = $ProcessInfo
  23. $Process.Start()
  24.  
  25. Start-Sleep -s 20
  26. $ProcessInfo.FileName = "$($env:SystemRoot)\system32\cmdkey.exe"
  27. $ProcessInfo.Arguments = "/delete TERMSRV/$Computer"
  28. $Process.StartInfo = $ProcessInfo
  29. $Process.Start()
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement