Created
August 24, 2015 14:55
-
-
Save DBremen/ae270d78e2a469398ddf to your computer and use it in GitHub Desktop.
Create default code template for PowerShell ISE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Edit-ISETemplate{ | |
$ISETemplatePath = "$([Environment]::GetFolderPath('MyDocuments'))\WindowsPowerShell\ISETemplate.ps1" | |
if (!Test-Path){ | |
New-Item $ISETemplatePath -ItemType File | |
} | |
psedit "$ISETemplatePath" | |
} | |
Register-ObjectEvent $psise.CurrentPowerShellTab.Files CollectionChanged -Action { | |
# files collection | |
$ISETemplate = "$([Environment]::GetFolderPath('MyDocuments'))\WindowsPowerShell\ISETemplate.ps1" | |
if (Test-Path $ISETemplate){ | |
try{ | |
$sender | | |
where {$_.IsUntitled -and $_.Editor.Text.Length -eq 0 } | | |
foreach { | |
$_.Editor.Text = Get-Content $ISETemplate -Raw | |
} | |
} | |
catch { | |
write-error $_ | |
} | |
} | |
} -SourceIdentifier CodeTemplate | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi. You have little mistake in line 3. You forgotten about variable $ISETemplatePath. That will be better
if (-not (Test-Path -Path $ISETemplatePath)){