首页 > 代码库 > Powershell Get File/Disk Size
Powershell Get File/Disk Size
知识点:1、获取路径中的文件夹:Get-ChildItem $startFolder | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object2、获取文件夹的总大小Get-ChildItem $i.FullName -recurse | Measure-Object -property length -sum3、 正则表达式:$DBname= $fullname -replace "^.*data\\" 、文档:\\localhost\D$\WENDY1\DBDATA\WENDY-MBX匹配:WENDY-MBX
$startFolders="FOLDERPATH1","FOLDERPATH2"foreach ($startFolder in $startFolders) { $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) $fullname=$i.FullName $SERVER=$fullname -replace "WENDY-MBX.*" $DBname= $fullname -replace "^.*data\\" $size=("{0:N2}" -f ($subFolderItems.sum / 1GB)) } }
$size=("{0:N2}" -f ($subFolderItems.sum / 1GB)) 保留小数点后两位$size=[math]::truncate($disk.size/1GB) 截取小数点,保留整数
$date=get-date).TOSTRING("yyyy-dd-MM")$servers= get-adcomputer -Filter {Name -Like "GAGA*" -or Name -Like "WENDY*" } -SearchScope Subtree -SearchBase "DC=WENDY,DC=CORP,DC=COM"foreach ($server in $servers) { $servername=$server.name $disks =Get-WmiObject Win32_LogicalDisk -ComputerName $servername -Filter "DriveType=‘3‘" forEach ($disk in $disks) { $DE=$disk.DeviceID $size=[math]::truncate($disk.size/1GB) $space=[math]::truncate($disk.freespace/1GB) } }
Powershell Get File/Disk Size
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。