bibi92
asked on
convert column MEM to int in format-table
Hello,
I search to convert MEM to int in this script :
Thanks
I search to convert MEM to int in this script :
If ($ProcessName -eq "ORACLE"{
$ProcessList = gwmi Win32_PerfRawData_PerfProc_Process | where {$_.Name -eq $ProcessName} | select IDProcess,Name,WorkingSetPrivate | sort WorkingSetPrivate -Descending | select -First $SelectFirst
}
else {exit 0}
$TProcess = @()
ForEach ($Process in $ProcessList) {
$row = new-object PSObject -Property @{
Id = $Process.IDProcess
Name = $Process.Name
MEM = $Process.WorkingSetPrivate /1024
}
$TProcess += $row
}
[int] $proc = $TopProcess | sort MEM -Descending | select MEM | ft -hide -autosize
Thanks
ASKER
Missing '=' operator after key in hash literal.
+ $row | <<<< Add-Member -MemberType NoteProperty -Name Id -Value $Process.I
DProcess
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : MissingEqualsInHashLiteral
Thanks
+ $row | <<<< Add-Member -MemberType NoteProperty -Name Id -Value $Process.I
DProcess
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : MissingEqualsInHashLiteral
Thanks
ASKER
I have created a new script and your code works but the type is always string thanks
Not sure why you have the table formatting in there, but this works fine for me:
$selectfirst = 3
$ProcessName = "Oracle"
$ProcessList = gwmi Win32_PerfRawData_PerfProc_Process | where {$_.name -like $ProcessName} |select IDProcess,Name,WorkingSetPrivate | sort WorkingSetPrivate -Descending | select -First $SelectFirst
$TProcess = @()
ForEach ($Process in $ProcessList) {
$row = new-object PSObject
$row | Add-Member -MemberType NoteProperty -Name Id -Value $Process.IDProcess
$row | Add-Member -MemberType NoteProperty -Name Name -value $Process.Name
$row | Add-Member -MemberType NoteProperty -Name MEM -value ($Process.WorkingSetPrivate /1024)
$TProcess += $row
}
[int]$proc = $TProcess | sort MEM -Descending | select -expand MEM
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The result of format-* cmdlets always is a string array consisting of the complete lines. That formatting should always be applied for display on screen, not for storing into a var.
Now I'm wondering if I misunderstood the question. Is it all about line 14?
@Qlemo - I'm curious about your statement, "The result of format-* cmdlets always is a string array consisting of the complete lines." The output of Format-* cmdlets is format data objects. I suppose it could be argued that format data objects are just strings, or have I misunderstood what you meant.?
@Qlemo - I'm curious about your statement, "The result of format-* cmdlets always is a string array consisting of the complete lines." The output of Format-* cmdlets is format data objects. I suppose it could be argued that format data objects are just strings, or have I misunderstood what you meant.?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
$selectfirst = 3
$ProcessName = "Oracle"
$ProcessList = gwmi Win32_PerfRawData_PerfProc _Process | where {$_.name -like $ProcessName} |select IDProcess,Name,WorkingSetP rivate | sort WorkingSetPrivate -Descending | select -First $SelectFirst
$TProcess = @()
ForEach ($Process in $ProcessList) {
$row = new-object PSObject -Property @{
Id = $Process.IDProcess
Name = $Process.Name
MEM = [INT]$Process.WorkingSetPr ivate /1024
}
$TopProcess += $row
echo $row.MEM
}
$ProcessName = "Oracle"
$ProcessList = gwmi Win32_PerfRawData_PerfProc
$TProcess = @()
ForEach ($Process in $ProcessList) {
$row = new-object PSObject -Property @{
Id = $Process.IDProcess
Name = $Process.Name
MEM = [INT]$Process.WorkingSetPr
}
$TopProcess += $row
echo $row.MEM
}
Open in new window