How can I get the PowerShell ISE to do syntax highlighting on files with a custom extension?
Asked Answered
K

3

12

I'd like to start using a custom extension for some of my Powershell scripts, but when I drag them into the PowerShell ISE, they are treated as plaintext, and I don't get any syntax highlighting. Is there anything I can do to get the ISE to recognize my custom file extension as a PowerShell script?

Kristofor answered 26/5, 2011 at 17:38 Comment(2)
I would like to know this too. But I have a feeling we will have to wait for MS to fix this.Neddra
Side note: found this question after all my syntax highlighting was green but that was cause I was using the "monochrome green" theme.Unmerciful
G
5

Can't be done because, as of the current version, the ISE determines whether to turn syntax highlighting on or not based on the file name extension: this behavior can't be changed as the recognized extensions are (unfortunately) fixed in the code.

They are, of course:

  • .ps1
  • .psm1
  • .psd1

For those who are wondering, the ISE determines this within the IsPowerShellSourceCodeFile internal property of the Microsoft.PowerShell.Host.ISE.ISEFile type, exported by the Microsoft.PowerShell.GPowerShell assembly. And no, reflection does not allow to cheat it, as trying to inject one of the supported extensions into the Extension property causes the ISE to crash.

Glume answered 29/8, 2011 at 14:34 Comment(0)
J
0

I'm going to say this is possible. The Powershell module here brings SQL highlighting to the Powershell ISE.

Judicative answered 17/9, 2011 at 17:58 Comment(0)
J
0

For me, the PS script file extension was inadvertently .ps, when I renamed it to have .ps1 extension, all the syntax highlighting revived. Hope this helps others.

Jenette answered 18/2, 2020 at 18:40 Comment(1)
This advice appears to already be stated in the accepted answer.Aerobatics

© 2022 - 2025 — McMap. All rights reserved.