r/PowerShell • • Apr 23 '19

Hacked together my first script in Powershell!

I'm an IT Intern for a small manufacturing company, and I've never dealt with powershell before. I was tasked with a really messy task of writing a script to open a program at startup, with the program existing in a folder labeled with an arbitrary name for each domain user.

I used a get-childitem and some parameters to find the first (and only) folder in the directory and then return it as a variable . I was able to plug that into an invoke-item and it opened. This simple task is calculated to save the company over 3000 dollars over the next month!

153 Upvotes

21 comments sorted by

21

u/[deleted] Apr 23 '19

Jesus $3000 by adding an item to launch at startup. Generally launching a program takes ~30 seconds. Must be an absolutely massive company!

16

u/gunnerman2 Apr 23 '19

One scenario I came up with given that it’s a small manufacturing company and the OP said that the folder name is arbitrary. If the folder name is arbitrary then that might imply that folder is named with some meaning with respect to the domain user as well.

It could be this program sets some defaults for some manufacturing process the user controls. Maybe failing to set the proper initial values results in manufacturing defects. Previously, users had to remember to run this program but inevitably someone would forget and end up wasting resources. With OP’s script there is no forgetting and they saved $3000.

7

u/jebhebmeb Apr 23 '19

Something like that. It’s a small manufacturing company and it’s the clock in/out system and also tests for electrostatic discharge. It was taking a long time for people to clock in because they had to find the file on each login. 10 min of productivity lost each day for each person clocking in is easily 3000, maybe more .

10

u/motorhead84 Apr 23 '19

Yeah if something as simple as running a program at startup via a script saves them $3k a month, I wonder how much I could save them lol

3

u/jebhebmeb Apr 23 '19

We had a virus attack and had to redo everything from the ground up, so it wasn’t really an issue before everything happened. Our director decided to change the way stuff is done, so it saved 3000, but that’s pocket change to the other stuff we are rebuilding and the savings they provide.

3

u/motorhead84 Apr 23 '19

Awesome--nice work! I bet it felt great to harness the power of, err, powershell...

14

u/teh_chaosjester Apr 23 '19

Problem is that the money you could save them will never land in your wallet :p

41

u/sleightof52 Apr 23 '19

That’s awesome!!! Congrats on your first super successful PowerShell script. Keep learning and scripting :)

15

u/Skepparbonk Apr 23 '19

Well done! That 3000 is gonna keep growing as well for each second saved and for each button press less etc.

A few things to thing about:

Get good at queries in powershell. If you know what you're looking for, why you're looking for it and in what format you need the information you've learned a lot along the way and in some cases most of the script . So getting comfortable with commands that collects information can be very helpful. Examples of things you can learn along the way of a get command: firewall blocks, account access rights limitations, format of directories/queries in different environments and how to convert the information into the format you need.

Also,

I've done plenty of inventory scripts and can write them almost on the fly as it is, which is very good skill to master.

Which user is logged in to PC X? - Powershell

Which PCs have a long up-time? - POWERSHELL

What graphics card does PC x have? - POWERSHELL!!

We need all the access groups to the file shares on this server! - POWERSHELL!!!!!

And when you notice there is a recurring query, save the script and share with colleagues. The time it saves is crazy.

However, automating things is one of the main strengths in my opinion. But if you use scheduled jobs, make sure its run with a service account with as few rights as possible. Its for security purposes mainly.

3

u/rrmcco04 Apr 24 '19

Some other things to save and keep handy are the building blocks for a different script. When I have something that I struggled with or some examples on how to do something, I save them in a doc called ps- building blocks so I grab them as needed. Things like making a menu function or the weird thing with arrays that I forget each time I need it.

8

u/2PhatCC Apr 23 '19

Congrats! I discovered Powershell while trying to figure out how to push a zip file to 48 different servers... Then I decided to try and figure out how to unzip that file on all the other servers. Now I'm addicted and have tried to automate most of my work. So beware, it's like a drug...

5

u/micromasters Apr 23 '19

That’s the thing isn’t it - nobody usually puts a dollar sign as to how much we save in man hours using automation. Now if only there’s a script for that ;)

4

u/v3ritas06 Apr 23 '19

Congrats! I never had much experience with PowerShell when I first started my job, but now I use it on a daily basis, & don’t know what I would do without it! Keep working with it because it does become very useful!

2

u/ReverendDS Apr 23 '19

Powershell wasn't even a thing when I started in IT.

Now it's such a prevalent part of MS Administration I don't know how I survived the dark times.

4

u/drox63 Apr 23 '19

OP. Document this experiance and save you script in a safe place. I can not tell you how many times I referanced previous work to make new tools.

PowerShell is incredibly versatile and can do just about anything on any system/OS.

One thing I wish I started doing sooner is utilizing version control. Keep your tool safe especially if you start handing them out to others.

I like coding PowerShell in visual studio code with PowerShell plugin. There are other platforms out there you should give them a try. I had a good learning curve jump when i moved off of PowerShell ISE. (Although I hear good things about ISE steroids).

3

u/clyde_drex Apr 23 '19

Woohoo my man! It reminds me of when I started at a small business and wrote some vb scripts that saved them a lot of time and money. Feels good man! :)

3

u/Marco_jeez Apr 23 '19

Congrats! I just started using Powershell less than 2 years ago myself; I had been on a helpdesk role, and started with "Learn Windows Powershell in a Month of Lunches". Within 2-3 months, I was able to get a promotion onto the Software Automation team at my company, where we use Powershell scripts mixed with Bigfix/Tivoli deployment to automatically install/uninstall software for our 12k device environment.

2

u/[deleted] Apr 23 '19

Great job! Keep on learning!

1

u/kieranjacobsen Apr 23 '19

Congratulations and welcome to the gang!

0

u/[deleted] Apr 23 '19

[deleted]

1

u/jchaven Apr 24 '19

He's a real IT boy/girl now.