码迷,mamicode.com
首页 > 系统相关 > 详细

Powershell Get File/Disk Size

时间:2017-07-08 20:22:28      阅读:318      评论:0      收藏:0      [点我收藏+]

标签:pat   compute   items   ring   知识   bsp   cat   filter   获取文件夹   

知识点:
1、获取路径中的文件夹:Get-ChildItem $startFolder  | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object
2、获取文件夹的总大小Get-ChildItem $i.FullName -recurse | Measure-Object -property length -sum
3、 正则表达式:$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

标签:pat   compute   items   ring   知识   bsp   cat   filter   获取文件夹   

原文地址:http://www.cnblogs.com/thescentedpath/p/filedisksize.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!