r/PowerShell • u/TheCallOfAsheron • Jun 15 '19
A general IT tool with GUI I created in PowerShell
Hello everyone,
I picked up PowerShell in the last year and pieced together a little tool that served as a project to learn as well as something I used daily and wanted to share what I built. I removed my companies name and internal links, so you may find specific buttons or links that won't function - for example the Active Directory related stuff would need to be pointed at your AD. I'm not an expert but I think there is some useful/fun things in there that someone else may be able to use in their own IT environment. Would love to hear any comments or thoughts on it!
Some of my favorite functions..
- The Local Admin tool lets you add a user to a remote PC's local admin group AND set a timer to remove them (via task scheduler)
- The Message button sends a pop-up message to a remote computer
- The speech button.. un-mutes, sets volume to 100%, and sends a customer text-to-speech message to a remote computer. For legitimate business functions only of course.
- The compare user groups button lets you compare 2 AD user's and if you want you can add user 1 into all of user 2's groups (mirror access).
Photo of the tool's different tabs: https://imgur.com/a/eYQXuPg
The first 3 tools on the tool tab are unfinished I think.. been a while.. but may be some good code there anyway. Let me know what you think!
47
u/icankickyouhigher Jun 15 '19
hi
this isn't really in a state to be shared as one big file like you have done. you have hardcoded servernames in there e.g "SERVER=DYNALGMVP14901"
if you want to share code, put it on github, that way as you make improvements and improve your code, the improvements are visible, rather than some random pastebin where it will be out of date as soon as you change anything
id suggest splitting out the stuff that is ready to use, modular and shareable, and only share that. nobody wants to trawl through one big pastebin.
hope this helps, cheers
17
u/TheCallOfAsheron Jun 16 '19
I appreciate the input! I'm not a developer and the intention was not to provide a polished evolving product.. this is just something I built and used myself. My advice would be check out the screenshot, or run the code, and if you see a component you are interested in then refer to the code by searching a keyword.
I am hoping to go through when I have time an re-work it to make it a agnostic tool that has no hardcoded anything, polish it up, and correct some of the wonky things using the methods and better practices I have learned along the way.
16
u/hackbinary Jun 16 '19
Your points about hard coded server names and posting to GitHub (or similar services like GitLab or Bitbucket) are completely valid.
Your points about not posting it until it is ready and/or modularising the code and posting the complete bits is just plain wrong. Software is almost never done, and a tool like this will almost certainly things that can be fixed or added.
It is best to post early and often, seek feedback, and iterate as fast as possible. I could speak at length about software engineering, and the benefits of DevOps methodologies.
3
u/larkeyyammer Jun 16 '19
I have coworkers with a similar mentality, i.e. "I don't want to show you my code if it's not finished." I hate hearing that because I know it means I'm never gonna see it. What I struggle to get across is why I want to see it, which is because I want to provide constructive feedback; it's the same reason I share my code. Thanks for that last paragraph, it concisely conveys what I try to tell others.
3
Jun 17 '19
"I don't want to show you my code if it's not finished."
What I struggle to get across is why I want to see it
If they understood that sharing the code helps them finish it well, rather than be judged, maybe they'd be more willing.
7
Jun 16 '19 edited Jun 06 '25
[removed] — view removed comment
22
u/TheCallOfAsheron Jun 16 '19
Thanks! There's a reason I named it the System Helper IT Tool (SHIT TOOL!)
8
u/TheCallOfAsheron Jun 15 '19
A couple notes..
May need to run as admin. It detects if it's not and automatically re-launches as admin normally.. but not sure if it's working on my home pc.
It creates a .txt log in the C:\Users\(user) folder
5
u/somanyads Jun 16 '19
Cool stuff! Moving a lot of your techs work into a single GUI saves them a ton of time. I, too, have created a tool for my techs/helpdesk as well. It's extremely useful for them and a huge learning tool for me. Have been working on it for a couple of years now and it has ballooned to over 20k lines (which I plan on sharing one day).
Do you hand code the GUI elements? Or use one of the tools mentioned below? I had work buy me Sapien PowerShell Studio -- love it and highly recommend it! Even bought myself a copy for home.
I am no expert by any means so I can't comfortably offer very many suggestions. One tip would be add a little telemetry to pass on to management - they love that stuff. I created a simple function to write a button click counter to the registry. Also helps me see what folks are using. An example for HKLM (which is pre-created on the form load (admin required)):
function Set-Telemetry #admin required to set HKLM
{
if ($($this.text) -ne "")
{
$text = $($this.text)
}
else
{
$text = $($this.Name) -replace "Button", ""
}
$telemetry = Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\<TOOLNAME> | Select-Object -ExpandProperty $text -ErrorAction SilentlyContinue
if ($telemetry -eq $null)
{
Set-ItemProperty -path HKLM:\SOFTWARE\<TOOLNAME> -Name $text -Value 1
}
else
{
$runcount = $telemetry + 1
Set-ItemProperty -path HKLM:\SOFTWARE\<TOOLNAME> -Name $text -Value $runcount
}
}Lastly, I have to give props to the LazyWinAdmin as he is the one who got me started with his free code. Might be some useful stuff in there for you as well. https://lazywinadmin.com/LazyWinAdmin_GUI/
2
u/TheCallOfAsheron Jun 16 '19
Awesome, thanks for the tip. I haven't got into using registry stuff for the tool, other then using PS to edit existing keys.. that's a great idea that could really add some cool functionality in the tool like custom user settings and saving paths etc.
2
u/somanyads Jun 16 '19
Welcome. I put that in HKLM to make it easier to grab and have a per-machine look at what is being run (in case it's a multi-user computer). My manager really likes seeing what everyone is clicking on. I do HKCU writes/reads to save/recall things such as the position and size of the window. Projects like this are great padding for your resume.
Very curious to see how you're doing your temp admin. That was a monster pain for me back in the day.
Thanks again for sharing.
2
u/TheCallOfAsheron Jun 16 '19
Yeah the temp admin tool was very useful for me. We used the Admin Clean tool (on tool tab) to remove all local admins throughout our environment that had accumulated over years.. and then we could just grant temporary admin to allow printer adds or software installs etc.
It creates a scheduled task that will run after the number of days you set, and the task runs the script to remove the user from local admin.
2
u/TheCallOfAsheron Jun 16 '19
I just checked out the LazyWinAdmin tool.. REALLY cool! Thanks for sharing, wish I had seen this a long time ago.
2
3
u/JeremyLC Jun 16 '19
On the "Main" tab, what is the unlabeled TextBox with the unlabeled small button next to it?
4
u/TheCallOfAsheron Jun 16 '19
We use randomly generated 20 digit passwords that reset daily for a specific service, so I just threw that box there to star-out whatever is pasted into it.. and the button just copies the field text to your clipboard. I place the password there in the morning and use it throughout the day. Probably not the most secure method but looks better than having it pasted in a .txt file to other users : )
3
u/shalafi71 Jun 16 '19
Needs some polish but seem extremely cool. Maybe this is what I'm doing tonight!
4
u/TheCallOfAsheron Jun 16 '19
Thanks! I am hoping to take the tool and re-work it using some of the methods I have learned, strip out any hard-coded or specific things and make it a universal tool that could just be run anywhere. I also have an idea to maybe make a template-tool that would create a more personalized tool for you.. such as add in your own companies name, connections, or allow some customization.
3
u/theClaz Jun 16 '19
I think is pretty cool actually. Not bad since you are still somewhat new...keep it up...
4
u/TheCallOfAsheron Jun 16 '19
Thanks, I definitely learned a lot as I went along creating it. I would like to re-work it from the ground up when I have time.
3
u/BoredComputerGuy Jun 17 '19
It is great that you are building a tool to make your life easier! A few thoughts:
You have some repeating code. DRY (Don't repeat yourself)! ie. logaction,addlist,importlist,etc. functions are repeated in multiple places. Using a single copy means that you don't need to figure out which one you are trying to use and when you make a change you don't need to change multiple locations.
You have try/catch blocks that don't actually handles errors(log only), they allow the code to continue to run which will may cause unknown behavior if the later code is not properly error handled. If you have code dependent on previous code they should probably be in the same try/catch block. You can handle different errors with multiple catch blocks per try block.
Great Job adding logging! I see far too many scripts and modules that don't include enough logging. You may want to consider having the ability to adjust logging level. ie Error only, Verbose, and debug
You should include a config file that can contain info such as server names, log file location, log level. Bonus points if you can edit settings in the gui.
Using Add-Member after creating an empty PS object is slower and more cumbersome than making an object with the needed properties that you can then set.
I would trim whitespace from user inputs in case there is an extra space or return added accidentally
You can use #region and #endregion to help collapse code and allow you to jump forward in your 2808 lines of code.
You don't verify that the AD import was imported properly. You could import when loading everything and then disable AD dependent buttons/functions if the module is not available.
I would run PS Script Analyzer on your script it shows some unused variables and left side $null comparisons, and a few other recommendations.
If you have any questions regarding these please let me know.
1
u/TheCallOfAsheron Jun 18 '19
That is excellent feedback, thank you for taking the time to take a look at it and write out such a well thought reply! I will definitely implement many of these suggestions when I get a chance to re-work the thing.
2
u/redditors_r_manginas Jun 16 '19
How hard is it to make powershell script have GUI?
2
u/TheCallOfAsheron Jun 16 '19
Really easy! It uses built in Windows components, so it can be built and used without any installs or changes on any Windows machine.
A simple online tool to create a layout is PoshGUI: https://poshgui.com/ It is very basic but can be useful especially if you are new to PS GUIs.
1
u/Lee_Dailey [grin] Jun 16 '19
howdy redditors_r_manginas,
it can be really annoying OR fairly easy. [grin] here's one easy way ...
dm3ll3n/AnyBox: Designed to facilitate script input/output with an easily customizable WPF window.
— https://github.com/dm3ll3n/AnyBoxhope that helps,
lee
2
u/foct Jun 16 '19
Wow. I can't believe I never thought to add tabs to POSH forms... 🤣
I have to add GUIs to a lot of my code so less technical people still use them. Unfortunately it's resulted in a bunch of scripts with somewhat similar, but specific, form layouts. I was thinking of making a generic launcher script to run any script from, but tackling the various functions in each script was getting stupid. Tabs would probably do the trick. 🤔
Thanks for sharing!
3
u/TheCallOfAsheron Jun 16 '19
Sure! Yeah the tabs are great and not hard to throw in. My plan for the tools tab was to keep a collection of all my separate but similar tools as well for my co-workers to use.
2
u/bestbackwards Jun 16 '19
Have some silver! I'd love to help you out with planning features, hosting a website and repository for this.
3
u/TheCallOfAsheron Jun 16 '19
Hey, thanks! I've got some good ideas for re-working it. When I started it I had no PS experience and just added to it as I learned, so there are a lot of things I would do differently or just using better practices. I'll keep you updated when I make some progress.
2
Jun 16 '19
I can't imagine that the text-to-speech feature of your tool goes over well at all, lol. Some people leave their volume very, very high.
2
u/TheCallOfAsheron Jun 16 '19
It actually forces the volume to 100% and if it is muted it will un-mute. Maybe I should add a disclaimer pop up confirmation...
2
u/shalafi71 Jun 16 '19
I send cats facts to a remote user. I know damned well she's sitting there in her underwear.
4
2
4
u/fire_over_the_ridge Jun 16 '19
Have use of this. We have an RMM but trying to get a remote user to find a certain machine can be hard. The system is on and the last logged in user got fired months ago and no one knew her or where she sat all day. Had a machine that the monitor was taken from and one could find it. Lot easier to play sound and have some one listen then wonder around looking at asset tags.
2
u/docNNST Jun 16 '19
Got to be an xkcd for this.
Which RMM? We're on Connectwise.
1
u/fire_over_the_ridge Jun 30 '19
Kaseya unfortunately. I swear this thing gets to more of pos the longer we have it.
2
u/Hagenist Jun 16 '19
I’ve had same situation. Numerous terminals scattered around a busy workshop without labels. When trying to find a particular machine I’ll remote on and play ‘Marco (polo)’ at full volume till foreman finds it.
2
1
1
1
u/trippingmonster Jun 24 '19
Hey, great work. If you haven't already, I can help you get this up on GitHub, refactor a bit, and reduce hardcoding so it can be useful for more people and people can contribute! The GUI work looks interesting - it's very Win32 (or is it Windows Forms?). I wonder if it's possible to modernize it by getting it on WPF or something.
1
1
u/absenthecon Jun 16 '19
!remindme 21 hours
0
u/RemindMeBot Jun 16 '19
I will be messaging you on 2019-06-16 22:23:00 UTC to remind you of this link.
CLICK THIS LINK to send a PM to also be reminded and to reduce spam.
Parent commenter can delete this message to hide from others.
FAQs Custom Your Reminders Feedback Code Browser Extensions
3
Jun 16 '19 edited Jun 07 '25
[removed] — view removed comment
3
u/TheCallOfAsheron Jun 16 '19
Sure! I used the speech component in a scheduled server task that would select a random sentence out of 50 or so and send it to my co-workers computer at a random time between 9-10AM.
1
Jun 19 '19
[removed] — view removed comment
1
u/AutoModerator Jun 19 '19
Sorry, your submission has been automatically removed.
Accounts must be at least 1 day old, which prevents the sub from filling up with bot spam.
Try posting again tomorrow or message the mods to approve your post.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
Jun 19 '19
[removed] — view removed comment
1
u/AutoModerator Jun 19 '19
Sorry, your submission has been automatically removed.
Accounts must be at least 1 day old, which prevents the sub from filling up with bot spam.
Try posting again tomorrow or message the mods to approve your post.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
31
u/Yevrag35 Jun 15 '19
At quick glance, I personally, try not to use ComObjects in my scripts. You're already loading Microsoft.VisualBasic, so use the Microsoft.VisualBasic.Interaction.MsgBox static method instead (or the System.Windows.Forms.MessageBox; either or). And speaking of loading assemblies, you only have to load them once in the script.
Another best-practice I would get in the habit of doing is to not to do empty if statements.
... is also more clearly written as:
I'm too tired to look over the rest right now (but I probably will later).