I'm looking for a way to automate testing my RDP connections for security software. Each week, I manually try logging into several RDP sessions, usually by entering the wrong username and password to see if the software blocks my IP as expected. While I know I could check if a port is open with Test-NetConnection, I'm struggling to find a way to script these login attempts. Is there anyone who can guide me on how to do this? Thanks in advance!
6 Answers
I thought there were multiple tools available for this kind of task in the hacking/Linux world, but I can't pinpoint a specific PowerShell solution. Aside from using `mstsc`, you might want to look into tools like RCMan, Royal TS, or mRemoteNG to save connections.
Are you already getting swamped with failed login attempts with your current setup? I wouldn't be surprised if the exposes RDP service is attracting attention.
Yes, you can script using `mstsc.exe`. It's a straightforward option to automate your login tests.
If you're not using a VPN, it's worth considering an RDP proxy or a third-party gateway like NetScaler. Just opening the port publicly isn't the safest move. I haven't found a solid solution out there that works for this specific scenario. I did come across some PowerShell scripts that deal with creating credential objects, but if the server has credential caching disabled (which it should in a secure environment), those options won't be effective.
I don't know much about a native PowerShell solution for this, but in my experience, I've used commands like `cmdkey /generic:"server-address" /user:"username" /pass:"password"` followed by `mstsc /v:server-address`, and then deleted the saved credentials. You'd need to check the output of the mstsc command to see if the connection failed. Just make sure the server supports saved logins!
You should check out my `invoke-mstsc` function on GitHub. It might be exactly what you need for scripting those RDP logins. You can find it at https://github.com/ztrhgf/LAPS.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically