ISE Addons, PowerShell, Scripting
comments 4

Adding header to newly created scripts in PowerShell ISE

Here is a simple function that you can use to add a script header everytime you create a new script file in PowerShell ISE. Jeff Hicks posted a function to create an addon menu option to do this. What I am showing here does not add any menu option. This function uses $psISE.CurrentPowerShellTab events and adds the header only to untitled files. 

How this one works is quite simple. We do an event subscription for the CollectionChanged event of $psISE.CurrentPowerShellTab object. Once we receive this event, we use the Add-Header function to insert the script header. While writing this, I found an issue (hopefully.!) with the ISE object model and I had to workaround that issue. The workaround I’d put is dirty but that is what I could find. Let me know if you have a better way to do this. 

You can copy & paste this to your ISE profile and every time you open a new file, either using CTRL+N or File -> New, the script header as stored in $header gets inserted. This is how it will look 

New ISE Script Header

New ISE Script Header

Do let me know your feedback on this.

Filed under: ISE Addons, PowerShell, Scripting


Ravikanth is a principal engineer and the lead architect for Microsoft and VMware virtualized and hybrid cloud solutions within the Infrastructure Solutions Group at Dell EMC. He is a multi-year recipient of Microsoft Most Valuable Professional (MVP) award in Windows PowerShell (CDM) and Microsoft Azure. Ravikanth is the author of Windows PowerShell Desired State Configuration Revealed (Apress) and leads Bangalore PowerShell and Bangalore IT Pro user groups. He can be seen speaking regularly at local user group events and conferences in India and abroad.