PoshCode Logo PowerShell Code Repository

Out-IseFile (modification of post by view diff)
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1623"></script>download | new post

PowerShells wrapping behaviour may be adequate for the console host. Using ISE it’s far from the optimal. But you don’t need to use the output pane. Send your output to a new ISE Editor. To see the difference just try:
get-help * | out-ISEFile

  1.  
  2.  
  3. function Out-IseFile
  4. {
  5.  
  6.     [CmdletBinding()]
  7.     param (
  8.         [Parameter(Position = 0, Mandatory = $True,  ValueFromPipeline = $True) ]        
  9.         $msg,
  10.         [Parameter(Position = 1, Mandatory = $False, ValueFromPipeline = $False)]        
  11.         $path = $null,
  12.         [Parameter(Position = 2, Mandatory = $False, ValueFromPipeline = $False)]        
  13.         $width = 2000,
  14.         [switch]$fl,
  15.         [switch]$passEditor
  16.     )
  17.  
  18.     Begin
  19.     {
  20.         $cnt = 0
  21.         $count   = $psise.CurrentPowerShellTab.Files.count
  22.         $null    = $psIse.CurrentPowerShellTab.Files.Add()
  23.         $Newfile = $psIse.CurrentPowerShellTab.Files[$count]
  24.         if ($path)
  25.         {    
  26.             $NewFile.SaveAs($path)
  27.             $NewFile.Save([Text.Encoding]::default)
  28.         }
  29.         $Editor = $Newfile.Editor
  30.        
  31.         filter Remove-TrailingBlanks { $_ -replace '(?m)\s*$', '' }
  32.         #filter Remove-TrailingBlanks { $_.TrimEnd() }
  33.     }
  34.  
  35.     Process
  36.     {
  37.         $cnt++
  38.        # if ($msg) { $msg | gm | Write-Verbose }
  39.        if ($cnt -eq 1)
  40.        {
  41.         $cmsg = @($msg)
  42.        }
  43.        else
  44.        {
  45.        $cmsg = $cmsg +  @($msg)
  46.        }
  47.     }
  48.    
  49.     End
  50.     {  
  51.         if ($cnt -gt 1)
  52.         {
  53.             $msg = $cmsg
  54.         }
  55.         if ($fl)
  56.         {
  57.             $msg = $msg |  Format-list | out-string -width $width | Remove-trailingBlanks
  58.         }
  59.         else
  60.         {
  61.             $msg = $msg | out-string -width $width | Remove-trailingBlanks
  62.         }
  63.         $msg = $msg +  "`r`n"
  64.  
  65.         #$Editor.SetCaretPosition($Editor.LineCount, 1)
  66.         $Editor.InsertText($msg)
  67.  
  68.         if ($passEditor){ $Newfile }
  69.        
  70.         Write-Verbose "Anzahl = $cnt   len msg = $($msg.count)"
  71.     }
  72. }
  73.  
  74. <#
  75.  
  76. $profile.psextended | out-IseFile -fl -verb
  77.  
  78. get-help *  | out-string -width 2000| out-ISEFile -verb
  79. get-help *  | out-ISEFile -verb
  80. get-help *  | out-ISEFile
  81.  
  82.  
  83.  
  84. $a =  $profile.psextended
  85. out-IseFile  $a -fl
  86.  
  87.  
  88. $a = get-help *  | out-string -width 2000
  89. out-IseFile  $a
  90. #>

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me