Fun with PowerShell
Hello Shavlik Community!
Last night I had the chance to take a condensed PowerShell class. I have been playing around with PowerShell for a while now as we have used it for a few supporting tools for NetChk Protect. I also have a bit of programming experience from High School and College, and from what I had played with PowerShell it seemed pretty easy and straightforward. A three hour introduction class showed me that I had only scratched the surface of PowerShell’s potential. If you’re looking for ways to simplify your IT management, here are a couple of the new things I learned and a few tools and scripts I have found really useful.
The PowerShell command line is great for quickly getting in and executing a few commands or building off of several commands to do more complex actions. Clear the screen or close the window and you may lose some information that could have been worth retaining. One of the first things the trainer showed us was the Transcript cmdlets. Start-Transcript and Stop-Transcript. Start-Transcript begins transcribing everything you do so you can review at a later time. You can also hit F7 like a regular command prompt. This shows you the last commands you executed so you can browse them and execute them again if desired.
Another very cool thing I learned last night was all the drive options you have. Like the traditional cmd prompt you can use cd, dir, ping, telnet, tracert, net commands etc. Try get-psdrive once. Notice you get much more than c:, d:, e:. You will also have Alias, Cert, HKCU, HKLM, WSMAN, Env, Function, and Variable. From PowerShell you can browse the registry or your certificate store or any of the others like the file system.
Get-Help can be done from the command line, but it gets very difficult very quickly to read through examples, details, etc. from a command line. You can run the PowerShell_ISE which gives you the ability to edit powershell scripts and has the command line built into the same interface. It has the full Windows Help built in as well so you can search it or browse it instead of fumbling through the help through the command line. Better yet there are other editors out there. PowerGUI is one that I have been using. A very powerful too, it color codes the nouns, verbs, operators, variables, comments, etc as you type them which gives a bit of visual order to your script writing. It can do all the same tab complete features that the PowerShell command line or ISE can do, but it also pops up details about the cmdlets you enter in so you can see details, input options, examples and so forth all as a pop-up note in case you need some details about it. For those of us who aren’t living in PowerShell it makes it much easier to write more complex scripts. If you are one who really wants to reverse engineer a script to dig deep and learn everything about it this may be distracting to use. Best part about PowerGUI is it is Free.
As far as practical use as it pertains to Shavlik products, here is an example of a script I have been playing with. I wanted to check several ports on a machine to see if I could scan a machine agentlessly with NetChk Protect. I found a really cool function on a blog post that worked great. It is called Test-Port. Once you create the .ps1 you can open it in PowerGUI and run it once and it loads it in PowerShell so at any time you can search for near anything and you will likely find it.
Chris Goettl
Agile Product Owner
Shavlik Technologies