zoukankan      html  css  js  c++  java
  • Powershell Get File/Disk Size

    知识点:
    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\" 、
    文档:\localhostD$WENDY1DBDATAWENDY-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)
                  }
    
        }
  • 相关阅读:
    Backtracking_37. 解数独
    Backtracking_131. 分割回文串
    DFS_90. 子集 II
    DFS_78. 子集
    DFS_216. 组合总和 III
    非对称加密和ssh免密登陆验证、邮件发送接收、网站CA证书验证
    hibernate一对多哪一方放弃权利?
    关于java转json的一些细节问题
    一个web程序中访问频率较高的url为什么要加时间戳?(特别是异步加载)
    阿里电面经验
  • 原文地址:https://www.cnblogs.com/thescentedpath/p/filedisksize.html
Copyright © 2011-2022 走看看