knowledge point: 1, get the folder in the path: Get-childitem $startFolder | Where-object {$_. Psiscontainer -eq $True} | Sort-object2, gets the total size of the folder Get-childitem $i. FullName- recurse | Measure-object-property length-sum3, Regular expression: $DBname = $fullname -replace "^.*data\\" , Documentation: \\localhost\d$\wendy1\dbdata\wendy-mbx match: wendy- mbx
$startFolders="FOLDERPATH1","FOLDERPATH2"foreach($startFolder inch $startFolders) { $colItems= (Get-childitem$startFolder| Where-object {$_. Psiscontainer-eq $True} | sort-Object)foreach($i inch $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)) retains two digits after the decimal point $size =[math]::truncate ($disk. Si ze/1GB) Intercept decimal point, retain integer
$date=get-date). TOSTRING ("yyyy-dd-mm")$servers= Get-adcomputer-Filter{Name-like "gaga*" -orName-like "wendy*"}-searchscope Subtree-searchbase"dc=wendy,dc=corp,dc=com"foreach($server inch $servers) { $servername=$server. Name$disks=get-wmiobject Win32_logicaldisk-computername$servername-Filter "drivetype= ' 3 '" ForEach($disk inch $disks) { $DE=$disk. DeviceID$size=[math]::truncate ($disk. size/1GB)$space=[math]::truncate ($disk. freespace/1GB)}}
Powershell Get File/disk Size