Public/Add-ISEText.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
function Add-ISEText { <# .Synopsis Add text to the bottom of current ISE File .EXAMPLE Add-ISEText -InputObject (Get-Content $profile) .EXAMPLE 'happy','go','lucky' | Add-ISEText .EXAMPLE Get-ChildItem 'C:\temp' | Add-ISEText #> [CmdletBinding()] [Alias('InISE')] Param( # Text to insert [Parameter( Mandatory, ValueFromPipeline )] [psobject[]]$InputObject ) Begin { if(-not ($psISE)) {throw 'PowerShell ISE Only'} } Process { foreach ($Object in $InputObject) { $LastLineLength = $psISE.CurrentFile.Editor.GetLineLength($psISE.CurrentFile.Editor.LineCount) + 1 if ($LastLineLength -ne 1) { $psISE.CurrentFile.Editor.SetCaretPosition($psISE.CurrentFile.Editor.LineCount,$LastLineLength) $psISE.CurrentFile.Editor.InsertText("`n") } $psISE.CurrentFile.Editor.SetCaretPosition($psISE.CurrentFile.Editor.LineCount,1) $psISE.CurrentFile.Editor.InsertText($Object) } } } |