Author Posts

April 16, 2016 at 4:49 pm

I've been trying for over 3 hrs now just to get the output from the below lined up on the left of a text box


function processes {

$HostName=$InputBoxHW.text;

$topprocs = Get-Counter -ComputerName $HostName '\Process(*)\% Processor Time' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty countersamples | %{New-Object PSObject -Property @{ComputerName=$_.Path.Split('\')[2];Process=$_.instancename;CPUPct=("{0,4:N0}%" -f $_.Cookedvalue);CookedValue=$_.CookedValue}} | ?{$_.CookedValue -gt 0}| Sort-Object @{E='ComputerName'; A=$true },@{E='CookedValue'; D=$true },@{E='Process'; A=$true }
$procs = $topprocs | ft @{E={"{0,25}" -f $_.Process};L="ProcessName"},CPUPct -HideTableHeaders -AutoSize

$outputProc.text = write $procs | Out-String
}

$outputProc = New-Object System.Windows.Forms.TextBox
$outputProc.Location = New-Object System.Drawing.Size(70,80)
$outputProc.Size = New-Object System.Drawing.Size(250,150)
$outputProc.MultiLine = $True
$Performance.Controls.Add($outputProc)

Sorry was going to paste a pic but can't

Anyway the txt is in the middle of the box with a space at the top

All i want it the process and %

Cheers

April 17, 2016 at 2:56 am

Default should be to align left. Have you tried forcing it with

$outputProc.TextAlign = 'Left'

The other thing check is that your input to the textbox does not have any spaces or formatting that's causing the problem. Try using the trim() method on the input to remove any white space.