Friday, February 3, 2017

Getting Started (An Introduction to PowerShell)

This is my first run through in making sure I’m writing at least one entry per week.  Before I could really talk about how I go about doing things, I thought I’d share how I started using PowerShell…

When first starting out with PowerShell, I had a feeling it was going to be an incredibly useful tool.  My first script wasn’t very good, but it was a way for me to uninstall an application from all the remote systems on my work network within a matter of a couple minutes.  It was meant to save time, which it did do that, but was horrible in its execution.  Not even clear on everything from memory, but it was calling VBScript, and Cmd.exe remotely through PSexec.  Looking back there’s so many different ways I could have made that work (and probably taken out too).  That’s for a different time though.

I determined after working on that little project, a different way of doing things was available, and I saw the writing on the wall that made me realize Microsoft was going to be doing a lot more to integrate PowerShell into its systems management.  Now, I’ve known myself long enough to know that unless I force myself to do something, I’m going to continue doing things in my own way, and knew I would need a push in the right direction.  This is where I decided to replace my startup environment to no longer utilize explorer.  From there, if I needed to do something, I figured, I’d better learn how to do it quickly, because no one was around to ask for help when I’m working by myself on a night shift, and a system is down.  In Windows 7 there’s a way to replace the default login environment, under HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon, and change the entry Shell to “powershell.exe”.

Once done, I rebooted.  Luckily, I knew some of the command line utilities w/ DOS as a backup and there were still applications the business relied on that worked were thick client apps, but my rules were simple:
  1. Anything I did within the operating system to interact had to be with PowerShell.
  2. I could not use the Internet to determine how to do anything.
  3. Everything I did had to use the corresponding cmdlet.  That meant I couldn’t just type explorer.exe, I actually had to run “Start-Process -FilePath c:\windows\explorer.exe”

While this probably wasn’t the best way to go about doing things, I learned the help structure was incredibly simple to work with, and just typing Get-Help would tell me everything I needed know. I ended up using PowerShell as my sole way of navigating my system, and after about 3 weeks was beginning to feel really comfortable with getting around.  I did end up giving up on the experiment because I liked having my desktop around.  I started doing as much reading on the topic as I could, and slowly began learning more about how to interact within .NET from PowerShell without needing to compile.  Once that little nugget of knowledge was dumped on me, and I could put my .NET development training to use without working in Visual Studio, things took off from there.  It would end up being a couple more years before I was able to start putting that knowledge to use, and start writing some more in depth scripts.  Beginning next week I’ll start looking more in depth at different commands and getting more into the nitty gritty (as they say).

No comments:

Post a Comment