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

10

u/zw9491 Oct 09 '19 edited Oct 10 '19

Wait. What. “Get ... Password”? That shouldn’t be able to happen.

Edit: okay... I guess plain text passwords in a column it is then

$MTPQuery = Invoke-DbaQuery -SqlInstance "Server" -SqlCredential $creds -Query "Select password from TABLE where UserName = @Username" -SqlParameters @{ Username = $Login} | select -expand password

Edit2: uhhhhh

$pw = get-content C:\PW.txt Edit 3: okay, being stored with DPAPI, 2 is mitigated at least

1

u/bajinabass Oct 10 '19 edited Oct 10 '19

Internal communication program that was custom built in house by our Director. So I'm just pulling from his db. And the $pw is from what I read about using stored encrypted credentials. If there is a better way, please let me know.

Edit: This is what I ran to make that pw.txt file:

$credential = Get-Credential
$credential.Password | ConvertFrom-SecureString | Set-Content c:\pw.txt

Referenced from here: https://interworks.com/blog/trhymer/2013/07/08/powershell-how-encrypt-and-store-credentials-securely-use-automation-scripts/

3

u/zw9491 Oct 10 '19

Passwords stored in a column was more a commentary on whoever set that up. That’s an absolutely horrible way to do it. If those are available, might as well use them. I’m assuming y’all were doing the same process manually, so nice job automating that shrugs in cyber security. I’m sure it’s some super business critical app that can’t just be replaced... so yeah....

Jumped the gun on the pw.txt.... got my functions confused with the naming/function of “ConvertFrom”. That’s the best way I know of at least without setting up some sort of password repository and grabbing it from there

2

u/bajinabass Oct 10 '19

Oh I totally agree it's a terrible way to hold passwords. But it is the brain child of the Director and his program. So I just went with what I could do in regards to that.