Hashtable Expression Unit format

How to format hashtable like Naumber+unit: 5 GB

Get-NetAdapterStatistics| Select-Object Name, @{Name="RE"; Expression={ [System.Math]::Ceiling($_.ReceivedBytes/1GB)}}

 

I didn’t get what you mean. Could you elaborate a little more detailed? Or could you show one or two examples?

I want the following:
Name RE Unit


Ethernet 0 GB
Npcap Loopback Adapter 0 GB
Ethernet 2 97 GB
NordLynx 0 GB
Helyi kapcsolat 2 0 GB
Ethernet 4 37 GB

or:

Name RE


Ethernet 0 GB
Npcap Loopback Adapter 0 GB
Ethernet 2 97 GB
NordLynx 0 GB
Helyi kapcsolat 2 0 GB
Ethernet 4 37 GB

If you just want to output the unit of measurement along with size you can simply add it as string like this:

Get-NetAdapterStatistics | 
Select-Object Name, @{Name = 'RE';Expression={[System.Math]::Ceiling($_.ReceivedBytes/1GB).ToString() + ' GB'}}

Alternatively you could use the format operator “-f”.

Here are some links to read more about:

https://social.technet.microsoft.com/wiki/contents/articles/7855.powershell-using-the-f-format-operator.aspx

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.1#format-operator–f

https://ss64.com/ps/syntax-f-operator.html

Have you tried my code suggestion? Or is there something wrong with it?

This seems to work as well:

Get-NetAdapterStatistics| Select-Object Name, @{Name=“RE”; Expression={[System.Math]::Ceiling($_.ReceivedBytes/1GB)}}, @{Name=‘Unit’; Expression={‘GB’}}