Size

dir <file>

Bytes

Get-ChildItem <file> | Select-Object Name, Length

Bytes

wmic datafile where name='C:\\file.txt' get FileSize

Bytes

Convert to KB and rounds to 2 decimal places:

Get-ChildItem <file> | Select-Object Name, @{Name="Size";Expression={[math]::Round($_.Length / 1KB,2)}}

Convert to MB and rounds to 2 decimal places:

Get-ChildItem <file> | Select-Object Name, @{Name="Size";Expression={[math]::Round($_.Length / 1MB,2)}}

Convert to GB and rounds to 2 decimal places:

Get-ChildItem <file> | Select-Object Name, @{Name="Size";Expression={[math]::Round($_.Length / 1GB,2)}}

Last updated

Was this helpful?