01 November 2020

Add Color coded PowerShell code to your Blogger page

I wanted a nicer way to show PowerShell code on my page here.
So after a little bit of searching a came across the PowerShell ISE.
Now thats nothing new, but what i didn't know is that you can add "add ons" to the ISE and with that it becomes even more fun.

To be able to add color coded PowerShell code to your blog install the module "IsePackV2"

If you haven't set Chocolatey and PSGallery as Packagesource and trusted them then run:
Get-PackageProvider -Name PSGallery -Force
Set-PackageSource -Name PSGallery -Trusted
Get-PackageProvider -Name Chocolatey -Force
Set-PackageSource -Name Chocolatey -Trusted
This Add on needs some additional modules so we'll install all in one go.
You can run this in PowerShell Ise or regular PowerShell but both must be run with elevated permissions:
Install-Module IsePackV2 -AllowClobber -Force           
Install-Module ShowUI -AllowClobber -Force            
Install-Module RoughDraft -AllowClobber -Force            
Install-Module Pipeworks -AllowClobber -Force            
Install-Module EZOut -AllowClobber -Force            
Install-Module ScriptCop -AllowClobber -Force            
Import-Module IsePackV2
When running the PowerShell ISE as Administrator and running Import-Module IsePackV2 there will be some error. I don't know where it comes from, i'll have to look in to that later.
But for now the thing your looking for is the add on we just added.





















The way this is as follows.
Your type some stuff in the script pane in the ISE.

















Select and copy it, go to Add-ons -> IsePack -> Edit -> Copy-ColoredAsHtml.
As soon as you click "Copy-ColoredAsHtml" it on your clipboard.
Now go to your blog editor and paste the text in the Html editor page:













And then it will look like this on your blog:



1 comment:

  1. Awesome, it helped me post the script with colors. Thanks a lot.

    ReplyDelete