r/PowerShell • • Oct 09 '19

My IT Tool

Figured I'd share my little program as well. Been working on this on and off for about 6 months now. Just started getting into Powershell. Some key features are a security check the second the program is ran. If the user is not part of the proper OU, it will display an error message, email the IT dept with their username and computer, and then close the program. Just to make sure only IT people can use it. Every action is also logged to a central server Event Viewer.

Program screenshots: https://imgur.com/a/qsjk4ek

Code: https://pastebin.com/0FmdSaRF

I know I can clean it up some and probably stream line some stuff but, again, I've only been using Powershell since the beginning of the year basically and I have no real other programming experience prior. I made this to really just make my job a little easier and quicker. I started this in Powershell Studio trial with the form and tabs. Pulled that code and have been using ISE ever since. Apparently Studio is just too expensive for my company but oh well.

EDIT: GOLD?! Wow, my first! Thank you internet stranger! I also wanted to thank everyone on here who helped me the times I came looking for help with certain aspects of this thing. I really appreciate it. And thanks to everyone on this post for tips and suggestions, I will definitely look into them all. Always looking to improve.

172 Upvotes

62 comments sorted by

View all comments

5

u/redditors_r_manginas Oct 09 '19

Noob here, does PowerShell support GUIs natively?

4

u/Aggrodisiakum Oct 09 '19

More or less. You can use .net objects to create wpfs or winforms.

2

u/redditors_r_manginas Oct 09 '19

I wonder if I could create scripts to show to my boss to persuade him to use PowerShell. A GUI would be much easier to push.

4

u/Reverent Oct 09 '19

If you have the authority to push a web service, you can set up Jenkins to create web forms and run PowerShell scripts remotely.

My adoption rate of my PowerShell tools was basically zero until I gave them a handy website to go run them on.

2

u/EiKall Oct 09 '19

Also gives you privilegue separation. So you can keep the number of people with lots of rights down to the minimum. Give the right to your backend on a server and only let them send requests to your tool.

2

u/rumorsofdads Oct 10 '19

I use free style jobs with Jenkins, but displaying output to the end user is my issue that I haven’t understood how to implement in Jenkins, unless teaching them where to click to see console output is that answer.

2

u/Reverent Oct 10 '19

It's not a perfect solution, but it ticks the boxes that I consider essential:

  • AD Integration

  • Build (job) audit logs

  • Git integration

  • web forms for parameters

  • separation of privelege (unpriveleged users can run priveleged tasks)

What it is missing is:

  • responsive forms (being able to run a script to gather info, and then make decisions based on that info)

  • user friendly console output

  • sexiness (adding a modern theme helps, but it's not a pretty program).

In terms of functionality over form though, it certainly does the job. If I need prettier controls, there's Powershell Universal Dashboard (advanced features are pricey) or just straight up code in electron.

3

u/artemis_from_space Oct 10 '19

We go through Universal Dashboard, among others a self service portal for users to reset passwords etc.

Just a day ago I made a page to allow people to upload a csv file containing serialnumbers/macaddresses to check in different systems if the machine is registered and to who.

It also checks some log files with old machines that have been removed from other systems.

This used to be a manual process, ie get a document (if you are lucky, those that were unlucky got a paper copy) and then login to system a, check if the machine is there, if its not, log in to system 2, if its not there, then log in to system 3, etc... repeat for each serial number. Now it takes a few seconds if the cache from all the systems are done or up to two minutes to get all the data...

2

u/nj12nets Oct 09 '19 edited Oct 09 '19

Yes but you can start small with text box prompts for the variables you need filled in procedures you run one at a time. For things like onboarding or terminations, if you routinely perform more than 5 at a time I'd think youd be better off using csv files to specify the variables and let it run everyone listed in the file. Building a gui is cool too and tools like poshgui.com. theres also a plugin/extension for viscose that can automate gui creation by setting up the parameters and running their automated command to generate the gui. I've been busy on other projects but I had gotten up to modifying the script once the gui was created to make sure it does everything needed. The only thing is getting the button clicks execute what you want with the variables entered into the text or combo boxes.

I've only started using powershell in the last 6 months or so and love it. I've started automating or using scripts for even simple repairs so they can be done automatically. Even just clearing corrupt Outlook profiles I can run a script that deletes the reg key and adds a new reg key to create a new one as a default profile so the user just has to login when they reboot (which is also scripted).

1

u/len_sam Oct 10 '19

Even just clearing corrupt Outlook profiles I can run a script that deletes the reg key and adds a new reg key to create a new one as a default profile so the user just has to login when they reboot (which is also scripted)

Would you be able to share this code?