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?
Share
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:
For those who are wondering, the ISE determines this within the
IsPowerShellSourceCodeFileinternal property of theMicrosoft.PowerShell.Host.ISE.ISEFiletype, exported by theMicrosoft.PowerShell.GPowerShellassembly. And no, reflection does not allow to cheat it, as trying to inject one of the supported extensions into theExtensionproperty causes the ISE to crash.