-
-
Notifications
You must be signed in to change notification settings - Fork 117
Closed
Labels
Description
When using scriptblocks, to define custom properties, the resulting width is way to large.
$props = @(
"Handles",
@{Name = "NPM(K)"; Expression = { [int]($_.npm / 1kb) } },
@{Name = "PM(K)"; Expression = { [int]($_.pm / 1kb) } },
@{Name = "WS(M)"; Expression = {
if ($_.ws -ge 500MB) {
"$([char]0x1b)[91m$([int]($_.ws/1mb))$([char]0x1b)[0m"
}
elseif ($_.ws -ge 250MB) {
"$([char]0x1b)[93m$([int]($_.ws/1mb))$([char]0x1b)[0m"
}
else {
[int]($_.ws / 1mb)
}
}
},
@{Name = "CPU"; Expression = { New-TimeSpan -Seconds $_.cpu } },
"ID",
@{Name = "ProcessName"; Expression = {
if ($_.ws -ge 500MB) {
"$([char]0x1b)[1;91m$($_.processname)$([char]0x1b)[0m"
}
elseif ($_.ws -ge 250MB) {
"$([char]0x1b)[1;93m$($_.processname)$([char]0x1b)[0m"
}
else {
$_.processname
}
}
}
)
Get-Process -Id $pid | New-PSFormatXML -Properties $props -ViewName WS -FormatType Table -Path c:\scripts\wsprocess.format.ps1xml -PassthruThe function makes a best guess on column widths but something looks wrong.
<TableColumnHeader>
<Label>ProcessName</Label>
<Width>210</Width>
<Alignment>left</Alignment>
</TableColumnHeader>Suspect the function is using the length of the scriptblock and not the value.