Powershell Get File/Disk Size

Posted The Scented Path

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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\\" 、
文档:\\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的主要内容,如果未能解决你的问题,请参考以下文章

powershell PowerShell:Get-Privilege

powershell PowerShell:Get-Handles

powershell PowerShell:Get-MicrosoftUpdates

powershell PowerShell:Get-NetPrefixPolicy

powershell PowerShell:Get-FileHash

powershell PowerShell:Get-ComparableVersion