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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-22 我要评论
想了解Powershell 之批量获取文件大小的实现代码的相关内容吗,在本文为您仔细讲解Powershell批量获取文件大小的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Powershell,批量获取,文件大小,下面大家一起来学习吧。

效果图:

核心代码

$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

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们