r/PowerShell • u/jebhebmeb • 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!
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
1
0
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!