Skip to main content

Tip - Add Syntax highlighting for PowerShell Code

There are lot of ways to add syntax highlighting to the PowerShell code in your blog, see the post by MVP Francios Xavier-Cat.

I just happened to come across one more which is pretty easy to use and best part is it uses a PowerShell module to do so.


Follow the below steps :
  1. Download the Copy to Colorized HTML module and put the extracted copy in your Modules directory.
  2. Add the below code to your ISE Profile, which will add a submenu and the "Ctrl+Shift+C" shortcut to copy the HTML content in your clipboard. 

$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add(“Copy As Colorized HTML”,{Copy-ColorizedHTML},“Ctrl+Shift+C”| Out-Null


The module has a single cmdlet called "Copy-ColorizedHTML" which copies the HTML content in your clipboard for use.

Once the content is copied to your clipboard just paste it to your blog.

NOTE - This method can also be used to while authoring an article for Technet Wiki.

see the animated GIF below:




Enjoy !



Popular posts from this blog

PowerShell + .psd1 files - decouple environment configuration data from code

What is environment configuration data?
Well, you might have heard the term 'configuration data' in usage with PowerShell DSC. The case for using configuration data is wherein all the input arguments are abstracted from the code being written so that this configuration data can be generated on the fly and passed to the underlying scripts or framework like DSC.

For some of our solutions being deployed at the customer site, we require a lot of input parameters e.g. different network subnets for management and storage networks, AD/DNS information etc.

Adding all these parameters to our input argument collector script was an error prone and tedious task since there were far too many input arguments. So instead of having a file to specify all input arguments was the preferred method.

This also helped us while troubleshooting the deployments since a local copy of the input arguments always persisted.


PowerShell + SCCM : WMI Scripting

Why should I use WMI, when there is a PowerShell module available for Configuration Manager (CM Module) already?

Well the cmdlets behind the scene interact with the WMI layer and if you know which WMI classes the corresponding cmdlet work with , it can be of help in future by :

Switching to native WMI calls when the CM cmdlets fail for some reason (probably bug in the CM Module).Making your scripts more efficient by optimizing the WMI (WQL query) calls, the cmdlet will query all the properties for an Object (select *) you can select only ones you need. Lastly no dependency on the CM Module, you can run these automation scripts from a machine not having the CM console installed (needed for CM module).Moreover ConfigMgr uses WMI extensively, you already have this knowledge leveraging it with PowerShell shouldn't surprise you. This post assumes you have been working with CM cmdlets (you already are versed with PowerShell), know where the WMI namespace for ConfigMgr resides and the basi…

Az.ResourceGraph - Search across all Subscriptions

Azure Resource Graph is an amazing tool in the belt of Az Ops team. It allows to quickly search across all your subscriptions (does it?).

Started using Az Resource graph with that pretext that the queries I ran will be run against all the subscriptions I have read access to, Yes it will but there is a catch here!

I mostly use Az.ResourceGraph PowerShell module (Why? another post)

Found the solution by digging into the source code for the Search-AzGraph cmdlet, if the subscriptions are not specified explicitly then the cmdlet uses a method named GetSubscriptions()

Below is a snippet of the method def:

The catch is that if no subscriptions are supplied it defaults to subscriptions in the default context. I am not really sure but some of the subscriptions which I can see when running Get-AzSubscription were missing when I ran the below:

(Get-AzContext).Account.ExtendedProperties.Subscriptions

So, the trick is to set the PSDefaultParameterValues for the Search-AzGraph cmdlet to include all the s…