Putting colorized Powershell code in your blog documentation


I love powershell, I love it’s power, flexibility and extensibility, however I I do most of my work in the shell because I cannot stand to use the ISE.  

The only feature of the ISE that I like it is the way it changes the color of variables, cmdlets, parameters etc.. since it makes it easy to differentiate the different parts of the script when proofreading.

Typically it’s a minor inconvenience, however when providing powershell scripts in Blogs or documentation the color helps spice things up.

Even though the ISE shows your code in color, you can’t just copy / paste it, instead you will need a Powershell module called PowerShellPack

http://archive.msdn.microsoft.com/PowerShellPack

Simply download and install, then just open the ISE and type “import-module isepack” in the command pane.   A new menu will appear called Add-Ons.

Choose IsePack \ Edit \ Copy-Colored (or CTRL+SHIFT+C) and the colorized version of your code will be in your clipboard…

 

Before :

(get-wmiobject Win32_cdromdrive).drive | foreach-object{$a = mountvol $_ /l;mountvol $_ /d;$a = $a.Trim();mountvol r: $a}

After :

(get-wmiobject Win32_cdromdrive).drive | foreach-object{$a = mountvol $_ /l;mountvol $_ /d;$a = $a.Trim();mountvol r: $a}

 

 

Comments (0)

Skip to main content