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 + 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 DevOps CLI : Query Release(s) definition for a Task status

Someone, asked me at work if I could generate a list of Release pipelines definitions which did not have a specific task (AzSK SVT task) missing or disabled.

This was more for an internal audit purpose and can definitely be built upon.
I recently read that Az CLI got an extension support for Az DevOps. Please read on the GitHub repository on how to install this extension for Az CLI.
Time to put this to try.

Below gist describes the steps I used in pwsh (PowerShell Core) with Az CLI & DevOps extension installed.

The above script should be self explanatory (read the comments). Please leave a comment if you have any queries.

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.