HOWTO: Identify and Run every valid Get-* cmdlet on your system

I recently found myself on a long bus ride with my laptop and no Internet connection.  I decided to create a PowerShell puzzle for myself to keep me busy until I reached my destination.  It ended up being kind of interesting so I wanted to share my puzzle and the solution with here.

Challenge

PowerShell has the concept of “Get-*” cmdlets where these will only retrieve information but will never change anything.  This makes Get commands safe to run, even if you don’t know what they do.   PowerShell ships with hundreds of Get cmdlets.  It would be great to know what kind of information each one provided.  To do that I’d need to run every Get command.  That’s simple enough but is complicated by the fact  that most Get- cmdlets come with multiple ‘parameter sets’ and many are configured with mandatory parameters.  This means that if we blindly run each command we’ll end up with a bunch of errors and prompts for user input.

So what we need to do is figure out which of the Get- commands can be run without passing any parameters.  We then also want to exclude commands that run properly but don’t return any data by default.

Solution

Check out the script below.  It will scan the system for every Get- command and then will figure out which ones can be executed directly without parameters and will actually return data.  It then runs all of those and returns the first 5 objects so you can get a feel for what kind of data is returned.  It will then display a report showing how many cmdlets met each criteria.  On my system for example we can see that 143 commands can be executed and return something useful just by typing the name of the command and hitting enter.

image

Read more

HOWTO: Build Tasklist for Studying for Microsoft Exams

This HOWTO is fairly specific to me but since I needed to document it anyway I figured I would share it in case in benefited others.
I have scheduled yet another Microsoft Exam for October.  One of the techniques I use during studying is to take the base “Skills Measured” list from Microsoft and build a checklist around it so I can keep track of what to review next.  To do this I traditionally copy and paste the list from the Microsoft exam site and painstakingly edit it to make it compatible with a commercial task tracking software I purchased called Swift To-Do List.  It’s mind-numbing repetitive work and I always tell myself I’m going to try and automate it but never do.  Well that ends today.

What am I talking about exactly?  Well let’s use an example.  I’m scheduled to write the 70-462 – Administering SQL 2012.  So I visit the site (https://www.microsoft.com/learning/en-ca/exam-70-462.aspx) and get something that looks like this:

image

There are a series of one level collapsible trees that contain all types of items on the exam.  The catch is rather than provide them in a list, the entries are separated by semi-colons.  What would be so much more useful is if I could transform that list into something like this:

image

Read more

HOWTO: Write Chinese on a Computer Keyboard

Last year I wrote a post on how to write Japanese on a western style keyboard. You can find that HOWTO along with some fascinating backstory here.  As I was already comfortable with Hangul (Korean), that meant that of the “big 3” Asian languages, I had a (very) basic comprehension of how to write with 2 of them.  Well, I figured today seemed like a great day to tackle what is perhaps the most daunting one of all.  That’s right, that means this HOWTO is going to cover how to write Chinese on your western keyboard!  However, before we can delve into the mechanics of how the process works, we need to understand a little bit of the history.

Disclaimer:  Everything you are about to read is based on my time spent with Google and Wikipedia.  I’ve almost certainly got some or even much of this wrong so if you do see something I have incorrect, please let me know in the comments and I can update it.  

First and foremost, it’s important to know that according to Wikipedia, “Chinese” is not one cohesive language but is rather a collection of between 7 and 13 “language dialects” that collectively form the “language family” that Westerner’s tend to think of as Chinese.  Of these dialects, by far the most common is one you’ve almost certainly heard of and that is called “Mandarin.” But that’s not the only one.  There are other dialects such as “Wu”, “Yue”, and “Min”.  What’s fascinating about these is that they are what is described as “mutually unintelligible” languages.  That is to say, despite sharing similar roots, a speaker from one dialect will not be able to readily communicate with a speaker from another dialect.  Think Spanish and Italian.  Same Latin root, but if a Spanish person travels to Italy, they would have difficulty communicating.

“Standard Chinese” or that is to say the “official” language adopted by the Chinese government is based off of the “Beijing dialect” and is also known as Pekingese.  It is specifically adopted by the “People’s Republic of China” (PRC) along with the “Republic of China” (aka Taiwan).  It’s also one of four official languages in Singapore.  There is another subset of Chinese called Cantonese which is considered more of a “prestige” language and is the official language of Hong Kong.  The important thing to take away from this is that, at least as far as my research has revealed for the level of detail I require for this post, all of the languages above use effectively the same written characters.  That is to say, if you know what you want to say, you should be able to follow the steps below to write your electronic message in any of the possible Chinese dialects.

The next thing to keep in mind is that generally speaking, like Korean and Japanese, a character generally represents one spoken syllable. That is to say, each “block” should represent one syllable. Also like Korean and Japanese but seemingly taken much further is the fact that a block/character may be a word on its own or a part of a polysyllabic word.  As you’ve likely heard, Chinese doesn’t have an alphabet in the sense that Westerners are familiar with.  Often times, a character (aka a series of strokes) represents an entire meaning on its own.  Put another way, each character is an atomic unit and cannot be further broken down.  It is estimated that there are over 60,000 unique characters in the Chinese language.  The good news is that research has suggested that a college educated Chinese citizen only needs to know about 3,000 to 4,000 characters to be considered fluent.

Read more

HOWTO: Backup and Restore FreeNAS Bootable USB Keys

I have several RAID5 NAS devices at home that are built upon the excellent FreeNAS.  One of the catches to using FreeNAS is that you must dedicate an entire drive to the operating system.  This means if you have say 3 1.5TB drives, you have to allocate (and therefore lose) 1.5TB of disk space to host a couple of hundred meg of operating system.  That’s obviously crazy and so the alternative is to simply boot off of USB.  I’ve been running this way for years and it’s been fantastic.  I got to thinking recently though – what happens if my USB key that I’m booting from fails?  I manually periodically backup the configuration so I can restore that but that only works once I’ve gone through all the trouble of rebuilding a new FreeNAS installation.  Wouldn’t it be easier if I could just clone the USB key and be done with it?

In my quest to do just this I discovered an excellent free piece of software called ImageUSB from Passmark. The software performed bit for bit duplication of a USB drive. It’s primary use case appears to be for mass duplication of USB drives (say to hand out at trade shows) but it has one feature in particular we want to take advantage of and that is the ability to save an image of a USB drive to a file.  Here’s how:

Read more

HOWTO: Auto add revision number to script with Subversion

As I have gotten increasingly comfortable with subversion and have started to develop a work flow, I ran into a problem. Most of the scripts I have added to my repository thus far have been self-contained scripts that’d I’d typically run straight from the repository folder.

But I recently ran into a use case where this doesn’t work. For the PowerGUI addon that I wrote, the production files must reside in %AppData%. This is of course not my repository folder so I needed a way to centrally manage my script in subversion and deploy to this new folder when I was ready.
The copy part was simple enough. I wrote a powershell script and placed it in the same SVN folder. It looks like this:

# Force copies files from repository to destination
# Copy; Deploy;

$SourcePath “c:\SVNScripts\Development\addon-scriptbrowser\”
$SourceFiles = @(“scriptbrowser.ps1”, “backuprepo.ps1”)
$DestPath “$Env:APPDATA\Quest Software\PowerGUI\Add-ons\Add-on.ScriptBrowser”
ForEach($File in $SourceFiles{ Copy-Item $SourcePath$File $DestPath -Force }

 

That’s easy enough. But for the centrally managed part, I realized that I could quickly run into confusion wondering if the version in the %AppData% folder was the most recent or not. Wouldn’t it be great if I could embed the version number directly into the file?  It turns out you can! Although it’s worth noting that it will be a little different than what you may be expecting at first blush.

Read more

HOWTO: Implement Source Version Control for Powershell Scripts with PowerGUI

As my knowledge of Powershell has increased, so too has the length and complexity of the scripts I create. My current record for example is a 387 line script. How did I keep track of all of the changes in a script of this length?

Not very well I’m afraid. I knew there had to be a better way. I was familiar with the concept of Source Control from the likes of Team Foundation Server but had never looked into it. As I sat down to figure out what my solution would look like, I identified the following requirements:

  • The source control system, whatever it is must be integrated with PowerGUI as that is my editor of choice
  • It must offer some kind of online component either that I host myself or is hosted by a third party so I can maintain a single repository from both work and home

As you can see, my requirements are rather universal and I’m sure are shared by other aspiring Powershell script writers around the world. So you can imagine my surprise then when upon starting my research into options I was surprised to find remarkably little information on this subject. There were pockets of information but they were scattered at best and others simply did not seem to exist.

That’s why I created this HOWTO. It represents many, many hours of trial and error on my part to come up with a Powershell centric source management system. Not only will this guide identify what you need and explain HOW to install it but it will also delve into WHY it is configured this way. My pain is your gain. So with that out of the way, let’s get started!

Read more

HOWTO: Write Japanese on a computer

I’ve decided to try to learn some of the basics of the Japanese language.  At first I thought I’d limit myself to memorizing some spoken phrases only but I found myself increasingly curious with how the Japanese writing system works.  I installed the Japanese keyboard on my tablet and… was immediately overwhelmed.  “How could anyone make sense of this?” I thought.  Rather than leave that as an open question however, I decided to answer it. I put the results of my research into a bite sized digestible blog post.  This is not designed to teach Japanese (because lord knows I’m the least qualified person in the world to do so) but rather describes how to simply write Japanese on a computer and in doing so demonstrates how incredibly complex the entire process is.  I have a whole new respect for the Japanese people for being able to make this language work.

If you’ve ever been curious how basic Japanese comes together into a coherent form but didn’t ever care enough to actually investigate yourself, this blog post is for you.

 

This HOWTO will describe what I have determined to be the requisite knowledge required to write Japanese on Windows Desktop Computer. In this example we will be using Windows 8.1.

  • First, Install the Japanese “Input Method Editor” (more commonly known as an IME)
    • Go to Start / Control Panel / Language
    • Choose Add a Language
    • Select Japanese and press OK.
  • You will now have the IME appear in the bottom right corner of your screen
  • By default, it will show up with an English “A” to indicate that you are typing with the English

  • Click on the “A” once and it will change to the character which also sounds like “ah” in Japanese
  • Right click on this system tray icon and you will be presented with a menu

Read more

HOWTO: Use Word as your WordPress Publishing Platform

Did you know that since Word 2007, Microsoft natively supports publishing directly to WordPress? It’s true! Why would you want this? In my case, I regularly create documentation at work that would likely be useful to a wider audience.

I create this documentation in Outlook and unfortunately due to the HTML rendering engine used in Outlook, the formatting never comes out right, especially around bullets. However, if you publish from Word, it takes care of all that translation for you!

At a high level, it works like this:

  • Enable the Publish as Blog Post function in Word
  • Create an account on your wordpress site to be used by the login page (Note the login happens over HTTP so you don’t want to use your administrator account)
  • Set up your account in Word and point it at your xmlrpc.php file on your server

The Details

  • Login to your wordpress site and go to Users and Add User
  • Pick a username and assign Editor permissions.

Read more