r/PowerShell • u/Federal_Ad2455 • Jun 14 '21
Script Sharing Fully automated RDP connection using LAPS password and PowerShell
https://doitpsway.com/fully-automated-rdp-connection-using-laps-password-and-powershell16
u/Tsull360 Jun 14 '21
What’s the use case for this solution? I regard a local account as the credential of last resort (I kind of want it to be painful).
3
u/nostradamefrus Jun 15 '21
Also curious. It’s kind of a cool process if for no other reason than showing the integration, but it makes no practical sense. LAPS needs a domain. Servers are joined to the domain. Domains have domain admin accounts. Just log in with your daily driver domain creds lol.
3
u/Vexxt Jun 15 '21
You should never log in to a workstation with a domain admin account, there are a million reasons why.
You also shouldnt have admin accounts that are admins on more than one machine or small cluster of machines as it allows lateral movement of say, ransomware, its basically keys to the kingdom. This is why LAPS exists.
2
u/nostradamefrus Jun 15 '21
I was just thinking about servers, not workstations. I didn’t read the whole article to see if it specifically was talking about workstations
2
u/Federal_Ad2455 Jun 15 '21
You shouldn't rds to servers with domain admin credentials either :-). If one of them will be compromised you are doomed... But that's another discussion (tier model)
1
u/Vexxt Jun 15 '21
Yeah fair enough, I only considered workstations because I couldn't imagine why you would use this on servers ever when you have PAM/JEA these days.
-1
u/Detach50 Jun 15 '21 edited Jun 15 '21
We don't allow local admin accounts rdp access to workstations, because they are for last resorts. In a case of last resort, my domain workstation admin account wouldn't work, so I would also have to leave my office anyway, so RDP with a local admin account is pointless in our environment.
However this could be useful for verifying LAPS passwords since the "not authorized for remote login" error is different from the "incorrect username/password" error. I built a script long ago that does exactly this when we first deployed LAPS.
Edit: mixed up my strikthrough and my
italicsbold.1
u/Poncho_au Jun 15 '21
Verify? LAPS by design verifies. You can’t have a LAPS password be different on your system than it is in AD.
I’d suggest anyone that tries to say that’s not true just didn’t realise the password was changed outside of LAPS unbeknownst to them.
6
3
u/jantari Jun 14 '21
mstsc.exe has command line options, you don't have to use AutoIt to work the GUI.
1
u/kojimoto Jun 14 '21
mstsc.exe has command line options, you don't have to use AutoIt to work the GUI.
It doesn't have parameters to define the username and the password in the command line
3
u/Vexxt Jun 15 '21 edited Jun 15 '21
It creates the cred object, so you just need to add the username.
Heres a better script that does the same thing i just wrote quickly.
function connect-lapsRDP { param( [Parameter(Mandatory=$false)][string]$adminUser = 'administrator', [Parameter(Mandatory=$true )][string]$computerName ) start-process cmdkey.exe -ArgumentList "/generic:TERMSRV/$computerName /user:$adminUser /pass:$((Get-ADComputer $computerName -Properties ms-Mcs-AdmPwd).'ms-Mcs-AdmPwd')" start-process mstsc.exe -ArgumentList "/v:$computerName" }1
u/jantari Jun 14 '21
Yea but it's my impression OP is using cmdkey for handling the username/password so that wouldn't be needed?
1
u/kojimoto Jun 14 '21
He is using Send-AU3Key from AutoIT to fill that information to the credentials window
1
1
1
-2
10
u/Digitaldarragh Jun 14 '21
I’m seriously investigating this kind of thing. An alternative is to use a product from a company called Beyond Trust. Again, it would enable people to log onto servers using a local administrator account. But is this not a step back? Surely it’s better to have an audit trail for each account? If Mr Bloggs is logging in at 10:30am and a service on that service stops at 10:31am, I know exactly who I need to go talk to. Sure. I can validate who looked up AD for the administrator password. But it’s not quite as clear cut as having the user name clearly displayed on the server. I am interested in other thought’s. Sorry if it seems like I’m taking over your thread. Your script is great and the idea is a really good one.