Tuesday, June 17, 2008

Help file of the day

About a month ago there was a interesting post on Mark Minasi's forum from Xenophane. It basically was about Don Jones recommendation for reading one Powershell help file a day to really get a solid foundation of how the cmdlets, providers, etc work.


My function, pretty different from Xenophane's. I put this in my profile so when PS starts I get a help file with it's full description with examples, and in pretty Green font.

   1:  function new-help {
   2:      # Create array of all help topics excluding the Alias topic
   3:      $helptopics = get-help * | ? { $_.Category -ne "alias" }
   4:  
   5:      # Create Random object for a random seed
   6:      $random = new System.Random
   7:  
   8:      # Get Random Help Topic name from array
   9:      $name = ($helptopics)[$random.Next(0, $helptopics.Count)].name
  10:  
  11:      # Save help file into a variable w/ Out-string
  12:      $helptopic = get-help $name -Full | Out-String 
  13:  
  14:      # Print the random Help file
  15:      write-host "Help file of the day" -fore green 
  16:      write-host $helpTopic -fore green
  17:      write-host "End of Help Tip of the day" -fore green
  18:  }

With PS V2 this can be really simplified with the Get-Random cmdlet.

Save the above function into your profile script then call it. Remember, you can't call a function before it's been defined.

No comments: