1

I'm trying to figure out how I can add some text such as MHz or GB to the results in the PowerShell table. Is it possible with a foreach loop?

Get-WmiObject Win32_PhysicalMmory | Format-Table Banklabel, Manufacturer, @{Label="Speed"; Expression={$_.ConfiguredClockSpeed}}, @{Label="Capacity"; Expression={[int64]($_.Capacity/1GB)}} -AutoSize 

Result 1

I have another way that comes close, but will not work with multiple results as it doesnt add the informtion into new rows.

$Disk = Get-WmiObject -Class Win32_LogicalDisk $DiskSpace = [int64]($Disk.Size/1GB) $FreeSpace = [INT64]($Disk.FreeSpace/1GB) $UsedSpace = (($DiskSpace-$FreeSpace)/$DiskSpace).ToString("P0") $OBJ = New-Object PSObject $OBJ | Add-Member NoteProperty "ID" ($Disk.DeviceID) $OBJ | Add-Member NoteProperty "Name" ($Disk.VolumeName) $OBJ | Add-Member NoteProperty "Format" ($Disk.FileSystem) $OBJ | Add-Member NoteProperty "Capacity" ("$DiskSpace-GB") $OBJ | Add-Member NoteProperty "Free Space" ("$FreeSpace-GB") $OBJ | Add-Member NoteProperty "Used" ($UsedSpace) Write-Output $OBJ | Format-Table 

Result 2

3 Answers 3

2

You can use much more complex expression, see following example:

Get-WmiObject win32_physicalmemory | Format-Table Banklabel, Manufacturer, @{Label="Speed";` Expression={$_.ConfiguredClockSpeed}}, @{Label="Capacity";` Expression={([INT64]($_.Capacity/1GB)).ToString()+" GB"}} -autosize 
Sign up to request clarification or add additional context in comments.

Comments

1

use the concatenation for your requirement.

replace

Get-WmiObject win32_physicalmemory | Format-Table Banklabel, Manufacturer, @{Label="Speed";` Expression={$_.ConfiguredClockSpeed}}, @{Label="Capacity";` Expression={[INT64]($_.Capacity/1GB)}} -autosize 

with this:

Get-WmiObject win32_physicalmemory | Format-Table Banklabel, Manufacturer, @{Label="Speed";` Expression={"$($_.ConfiguredClockSpeed) MHz"}}, @{Label="Capacity";` Expression={"$([INT64]($_.Capacity/1GB)) GB"}} -autosize 

Hope it helps.

Comments

0

Because you're already using calculated properties it's easy to extend them. It depends what you try to achieve. I would recommend to place the unit into table header like this:

Get-WmiObject win32_physicalmemory | Select-Object -Property Banklabel, Manufacturer, @{Name='Speed in MHz';Expression={$_.ConfiguredClockSpeed}}, @{Name='Capacity in GB'; Expression={[INT64]($_.Capacity/1GB)}} 

If you really need it in the table you could do it like this:

Get-WmiObject win32_physicalmemory | Select-Object -Property Banklabel, Manufacturer, @{Name='Speed';Expression={"{0} MHz" -f $_.ConfiguredClockSpeed}}, @{Name='Capacity in GB'; Expression={"{0} GB" -f [INT64]($_.Capacity/1GB)}} 

But this way you loose the possibility to calculate with your results. It's just strings now.

2 Comments

He is more looking it in the results and not in column names.
That's why I posted both. ;-)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.