<# .Synopsis Out-Textbox.ps1 outputs object to a resizable text box for display .DESCRIPTION Out-Textbox.ps1 outputs object to a resizable text box for display .EXAMPLE Output object to textbox with custom "My Results" title $data | out-Textbox -Title "My Results" .EXAMPLE Output object to textbox with default "Results" title Out-Textbox $data .Notes Alan dot Kaplan at VA dot Gov ver 1.0 12-8-2015 ver 1.1 8-18-2017 Fixed wait for all data before displaying, compacted code, added dot source reminder #> function Out-TextBox { [CmdletBinding()] Param ( # StrText help description [Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)] $objIn, # Title help description [Parameter(Mandatory=$False, Position=1)] [string]$Title = "Results" ) begin { $txt = @() } process { $txt += $objIn } End{ #Make sure text is string, trim leading and trailing spaces $strText = $($txt| out-string).Trim() ######################################################################## # Initial Code Generated By: SAPIEN Technologies PrimalForms # (Community Edition) v1.0.10.0 # By: Alan Kaplan ######################################################################## #region Import the Assemblies Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Drawing #endregion #region Generated Form Objects $DisplayForm = New-Object System.Windows.Forms.Form $textBox = New-Object System.Windows.Forms.TextBox $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState #endregion Generated Form Objects #---------------------------------------------- #region Edited Generated Form Code $System_Drawing_Size = New-Object System.Drawing.Size(800,550) $DisplayForm.ClientSize = $System_Drawing_Size $DisplayForm.Name = "DisplayForm" $DisplayForm.StartPosition = "CenterScreen" $DisplayForm.Text = $title $DisplayForm.AutoScale = $true $textBox.Dock = 5 $System_Drawing_Point = New-Object System.Drawing.Point(1,1) $textBox.Location = $System_Drawing_Point $textBox.Multiline = $True $textBox.Name = "textBox" $textBox.ScrollBars = 3 #From above $textBox.Size = $System_Drawing_Size $textBox.TabIndex = 0 $textBox.Text = $strText.trim() $textbox.AutoSize = $true $Font = New-Object System.Drawing.Font("Courier New",12,[System.Drawing.FontStyle]::Regular) $textBox.Font = $Font #This bit de-selects text in box if($displayForm.CanFocus){ $DisplayForm.Focus() }else{ $DisplayForm.Select() } $DisplayForm.Controls.Add($textBox) #endregion Edited Generated Form Code $DisplayForm.ShowDialog()| Out-Null } } ### Dot Source Reminder Begins ### $ScriptPath= $MyInvocation.MyCommand.Definition.ToString() #you can hard code name of function as $fn #$fn = "Verb-Noun" #Presumes function name is same as script Name $fn = $MyInvocation.MyCommand.Name.Replace(".ps1","") $ScriptTxt = Get-Content $ScriptPath $MoreTxt = [regex]::Split($ScriptTxt,'Reminder Ends ###')[2] if ($MoreTxt.Length -lt $fn.Length){ if (($host.Name).Contains("ISE")){ Write-host "`nYou have loaded the advanced function `"$fn`"" -F Green "`tUse `"Get-Help`" for information and usage, Ex:`n`tPS C:\> Get-Help $fn -detailed`n" }ELSE{ if ($MyInvocation.InvocationName -ne '.') { Write-Host "`nThis advanced function must be dot sourced to run.`n" -F Green "Load example:`n`tPS C:\> . `"$ScriptPath`"`n After loading, use `"Get-Help`" for information and usage, Ex: PS C:\> Get-Help $fn -detailed`n" #Pause if launched from shell with "Run with PowerShell" if ([regex]::IsMatch([Environment]::GetCommandLineArgs(), 'powershell_ise') -eq $false){Pause} } } }#End Function ### Dot Source Reminder Ends ###