I am trying to use powershell to setup a process that off boards users and doing the AD side of things is great but I am not sure how to use powershell to interact with our other software that only has a gui.
For example user management in studio3T where they only have a web UI or an application that you can download and run locally.
There are a few options:
- Use AutoIT or some similar automation framework. Generally, this is pretty easy and gets the job done. Your security folks may hate you (AutoIT binary hashes are basically all assumed to be malware IoCs at this point),
- Depending on how the GUI works, you may be able to reverse engineer the calls made by the application and just make those calls yourself. For a Web UI, you can use something like BurpeSuite or even just the FireFox developer tools to catch the web calls and then modify/replay those as desired. For a console application, it could be trickier, as you may need to either load the software’s libraries (DLLs) or figure out database calls. It all depends on how the user data is stored and updated.
- Using P/Invoke you can load several functions from the Win32 API, specifically FindWindowEx and EnumChildWindows to locate the GUI application and any specific form items you want to manipulate (e.g. TextBoxes to fill, Buttons to click). You can then modify properties or send clicks. You’ll probably hate yourself at the end of this project, but you’ll learn a lot.
oh man I have so many things to learn.
I have it on good authority that you currently have a project idea which you can use to pick one (or more) of those paths and start learning. ;-)
For example user management in studio3T
Not sure how I missed this on my first read of your post. But, this looks like a fancy front end to making MongoDB calls. That makes life easier, MongoDB has a well documented API and a driver for C#. As an aside, if you want to get really good at PowerShell, getting a basic working knowledge of C# and .Net in general is really helpful. For the lazy (and I always like lazy), there’s even a pre-built MongoDB module on the PowerShell Galley called Mdbc. There is also the Project’s GitHub Page which has a lot of useful info.
Granted, this path likely means learning enough about MongoDB to create/delete/modify users. But you came here expecting a load of homework, right? Also, this is a good excuse to spin up a docker container running MongoDB and go hog wild breaking the fuck out of it (just call it “research” if management asks). And who doesn’t love breaking stuff?
I’d also note that you may be able to get some help along the way by capturing the network traffic to the server caused by the Studio3T GUI. WireShark can capture the traffic to/from the DB server and you can read that to reverse engineer some of the calls you care about. Just, make sure you talk to your security folks before you download/install WireShark. If they are worth their salt, they’ll understand an engineer installing/running wireshark, it just makes their day easier if they know the alert is coming first. Assuming the GUI isn’t complete shit, it may encrypt traffic. This can be dealt with by using the SSLKEYLOGFILE environmental variable. In most cases, this results in the TLS keys being saved to a file and that can be imported into WireShark.
Good luck, and have fun!
Api if it has one. Otherwise AutoIt or Autohotkey
You can also use OCR libraries to read text or match colors.
Python can do it quite well. Look for certain pixels, click if they have a certain value.
As others have said it’s better to use other methods like apis where there is context but it’s definitely doable.
If it’s on the web, I’ve used selenium for years to get around apis and websites that don’t support it.
I wouldn’t personally
What if your automation clicks the wrong button after an update? GUI is for humans not scripts.
I mean yes, but updates can also break scripts. I’d say less likely, but if the automation solves an annoying issue, just go for it. It’s good to understand though that the automation needs adjustment from time to time
but im lazy and I dont want to have to manually do it every time 😅
Its been quite a few years, but used Selenium to interact with GUIs for these kind of things. This included onboarding/offboarding tasks.
As others have said - automating something with a GUI can get nasty. That being said, PowerAutomate isn’t terrible, nor is UiPath. I’ve also used Autohotkey, but it has a steep learning curve.
Last time I wanted to automate something on Windows (3 years ago), PowerAutomate did the job quite well.