手机
当前位置:查字典教程网 >脚本专栏 >PowerShell >Powershell 之批量获取文件大小的实现代码
Powershell 之批量获取文件大小的实现代码
摘要:效果图:核心代码$startFolder="D:"$colItems=(Get-ChildItem$startFolder|Where-Ob...

效果图:

Powershell 之批量获取文件大小的实现代码1

核心代码

$startFolder = "D:" $colItems = (Get-ChildItem $startFolder | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object) foreach ($i in $colItems) { $subFolderItems = (Get-ChildItem $i.FullName -recurse | Measure-Object -property length -sum) $FileSize="{0:N2}" -f ($subFolderItems.sum / 1GB) $Unit='GB' if($FileSize -lt 1) { $FileSize="{0:N2}" -f ($subFolderItems.sum / 1MB) $Unit='MB' } write-host $i.FullName ' -- ' $FileSize $Unit -fore green }

注意:如果是第一次运行需要开启执行脚本权限。

在powershell中运行如下命令,然后 Y 确认即可。

开启:set-executionpolicy remotesigned

关闭:Set-ExecutionPolicy Restricted

【Powershell 之批量获取文件大小的实现代码】相关文章:

Powershell实现加密解密文本文件方法实例

Powershell小技巧之找出最大最小值

PowerShell定义函数参数的2种方法和传参方法实例

Powershell小技巧之从文件获取系统日志

PowerShell数组结合switch语句产生的奇特效果介绍

Python中调用PowerShell、远程执行bat文件实例

Powershell中调用邮件客户端发送邮件的例子

PowerShell String对象方法小结

Powershell小技巧之查找脚本中的函数

PowerShell中的$Input变量使用实例

精品推荐
分类导航