Share a PowerShell script used in a project of your own writing, this script is very simple, the function is not complex, the main role is to count the size of all subfolders under a folder, this is to cooperate with statistics collected from the individual user computer information, Each collected information is archived to a folder named after the computer name, but which calculation failed to collect? What is the size of the data collected by everyone? This needs to be counted again.
This feature of the software in fact, there are many online, but for an IT pro, what things are not a good habit of asking Baidu, their hands and clothing, anyway this is a very simple function does not need too complex logic, direct use of PowerShell to get it done
Look at the code below.
function FileSize ([string] $filepath) {if ($filepath-eq $null) {Throw "path cannot be empty"}dir-path $filepath | foreach-object-process {if ($_.psiscontainer-eq $true) {$length = 0dir-path $_.fullname-recurse | foreach-object{$length + = $_. Length} $l = $length/1kb$_.name + "folder size: {0:n1} KB"-F $l}}}filesize-filepath "e:\ system file dump \ Desktop \test"
is a very simple function, to see the folder structure of testing, test is the parent directory, in this directory there will be many subdirectories, each subdirectory may also be nested subdirectories
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6C/D2/wKioL1VTTZuRtxIMAAJv0W-fTJ8698.jpg "style=" float: none; "title=" Qq20150513210448.png "alt=" Wkiol1vttzurtximaajv0w-ftj8698.jpg "/>
In addition, these folders will contain many files.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6C/D7/wKiom1VTTCHBNTmMAAC2mzHXofE576.jpg "style=" float: none; "title=" Qq20150513210456.png "alt=" Wkiom1vttchbntmmaac2mzhxofe576.jpg "/>
After executing this function, you can see the results of the statistics as follows, in order to watch the statistics converted into the form of KB
Filesize-filepath "e:\ system file dump \ Desktop \test"
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6C/D7/wKiom1VTTCHAPqQ9AAET2oq6s_U019.jpg "style=" float: none; "title=" Qq20150513210518.png "alt=" Wkiom1vttchapqq9aaet2oq6s_u019.jpg "/>
Share this today and try to write more useful scripts later.
This article is from the "Just Make It Happen" blog, so be sure to keep this source http://mxyit.blog.51cto.com/4308871/1651080
Statistics subfolder size using PowerShell