以 GB 为单位显示磁盘大小和可用空间 [英] Display Disk Size and FreeSpace in GB

查看:53
本文介绍了以 GB 为单位显示磁盘大小和可用空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一行代码可以以 gb 而不是 mb 显示逻辑磁盘的可用大小和磁盘空间?我尝试进行了一些研究,但找不到一个班轮,我确实尝试过将其除以 1GB,但这不起作用,我该如何实现?

Is there one line of code that will display free-size and disk-space of your logical disk in gb instead of mb? I tried doing some research but I couldn't find one liner, I did give this an attempt which was to divide it by 1GB, but that didn't work, how can I accomplish this?

gwmi win32_logicaldisk | Format-Table DeviceId, MediaType,Size,FreeSpace /1GB

推荐答案

尝试计算属性.我还会添加 [math]::Round() 来缩短值:

Try calculated properties. I would also add [math]::Round() to shorten the values:

gwmi win32_logicaldisk | Format-Table DeviceId, MediaType, @{n="Size";e={[math]::Round($_.Size/1GB,2)}},@{n="FreeSpace";e={[math]::Round($_.FreeSpace/1GB,2)}}

n 代表 namee 代表 expression.您也可以使用全名,但如果您要编写多个计算属性,那会浪费空间.

n stands for name and e for expression. You could use the full names too, but it's a waste of space if you're writing multiple calculated Properties.

这篇关于以 GB 为单位显示磁盘大小和可用空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆