DEV Community

Cover image for Why You Should Use PowerShell
Milecia
Milecia

Posted on • Edited on

Why You Should Use PowerShell

There are times you need things to run automatically for you when it comes to deploying websites. It's not that deploying them is hard, it's just repetitive. At some point it may be easier for you to write a short little script that will do all of the legwork for you. That's where PowerShell can come in. PowerShell is a game-changer when you have access to the server your website is on.

Why you would use it

Let's get straight to the point. You should consider using PowerShell if you have tasks that you want to run automatically to manage operating systems and their processes. So you could write a script that changes someone's background every time they click a certain button. Or you could do something like write a script that restarts the process for your website after all of the files have been uploaded.

There are a lot of uses for PowerShell when you have a lot of processes that need to run at specific times under certain conditions and you don't want to wait for each process to finish to start the next. You can even do things like convert Excel files into Word files if you need to make a report based on the same data every time.

Another important reason you might use PowerShell is if you want to keep consistency in your processes. Once you write a script, it will execute the exact same each time. You don't have to worry about missing a step or having a typo somewhere. It even creates logs so that you can track any errors that occur at each and every step of the process.

How to use it

PowerShell is both a command line interface and a scripting language. You do have the option of using its integrated scripting environment if you don't want to use the command line in the beginning. The scripting language is a little similar to Perl and the command line is similar to the terminal in Linux.

One important distinction to make here is that PowerShell is not the same as the Command Prompt. PowerShell has more flexibility to work with different programs on the system instead of just the DOS. Another thing you need to know about PowerShell is that it was built using the .NET framework.

That's an interesting point because it means your scripts can use .NET interfaces and you can embed PowerShell scripts into your .NET code. This feature gives you so much more power than the Command Prompt does. You can do actual operating system management in the back-end of your code. If you can implement this the correct way, you have the potential to save yourself a lot of time.

PowerShell also uses cmdlets instead of commands. This subtle, but powerful difference lets you have direct access to the registry management and other system admin functionality. You can use this access to make updates to user permissions and other data on the system.

Getting started

You have the ability to really work with your data using PowerShell because the data from the cmdlets are objects. Playing with the clipboard cmdlets will give you some good examples of how great it can be to have your data stored in objects.

Actually, playing with the clipboard cmdlets is a great way in general to start understanding the PowerShell. It's not overly complex where you will get lost but it's not so simple where it seems pointless. Check out these two cmdlets just to get you started: Get-Clipboard and Set-Clipboard.

It might take a little time to get used to using PowerShell and to learn to see opportunities for using PowerShell, but that's like with anything else. And just like with anything else, once you really understand PowerShell, the way you work will change. Or at the very least the type of pranks you can play on your friends will be next level.

Have any of you written any crazy Powershell scripts to prank people? Or for you know, useful stuff? I'd love to hear your experiences in the comments. 🙂


Hey! You should follow me on Twitter because reasons: https://twitter.com/FlippedCoding

Top comments (3)

Collapse
 
cmohan profile image
Catherine Mohan

I've been coding almost exclusively in Powershell for the last 6 months. I'm an IT tech and I write scripts, modules, and applications for use at work. No prank scripts yet but I have built a neat, little app that will remotely pull memory usage data from all computers listed in a CSV file and format it nicely into an Excel spreadsheet. It runs in the background on my computer pretty much constantly. Powershell is actually quite powerful. I find new things to do with it every day.

Collapse
 
rtxa profile image
rtxa

What about using Python instead?