PowerShell: Get Folder Sizes on Disk in Windows

The most of Windows customers get used that the simplest technique to examine the dimensions of a folder is to open the folder properties in Windows Explorer. More skilled customers desire to make use of instruments like TreeSize or WinDirStat. However, if you wish to get an in depth statistics on the dimensions of folders in the precise listing or exclude sure file sorts, you’d higher use the PowerShell scripts. In this text we’ll present you the way to shortly get the dimensions of the precise folder on the disk (or all subfolders) utilizing PowerShell.

Tip. To get the dimensions of the precise folder on the disk, you can too use the CLI device du.exe.

You can use the Get-ChildItem (gci alias) and Measure-Object (measure alias) cmdlets to get the sizes of information and directories in PowerShell.

The first cmdlet permits you to get the listing of information in the desired listing by the sure standards, and the second performs an arithmetic operation.

For instance, to get the dimensions of c:ps folder, run the next command:

Get-ChildItem c:iso | Measure-Object -Property Length -sum

get-childrenitem - powershell - folder size

As you possibly can see, the entire dimension of information in this listing is proven in the Sum subject and is about 2.1 GB (the dimensions is given in bytes).

To convert the dimensions into extra handy MB or GB, use this command:

(gci c:iso | measure Length -s).sum / 1Gb


(gci c:iso | measure Length -s).sum / 1Mb

To around the consequence to 2 decimals, run the next command:

" GB" -f ((gci c:iso | measure Length -s).sum / 1Gb)

PowerShell Calculating Folder Sizes - gci and measure sum

To calculate the entire dimension of all information of a sure sort in a listing, use this command (for instance you wish to get the entire dimension of all ISO information in a folder):

(gci c:iso *.iso | measure Length -s).sum / 1Mb

get folder size in MB using powershell

The instructions proven above will let you get solely the entire dimension of information in the desired listing. If there are subfolders in the listing, the dimensions of information in the subfolders gained’t be calculated. To get the entire dimension of information in the listing taking subfolders under consideration, use the –Recurse parameter. Let’s get the entire dimension of information in the C:Windows listing:

" GB" -f ((gci –drive c:Windows –Recurse -ErrorAction SilentlyContinue| measure Length -s).sum / 1Gb)

To have in mind the dimensions of hidden and system information, I’ve used the –drive argument as nicely.

So the dimensions of C:Windows on my native drive is about 16 GB.

Tip. In order to stop listing entry errors, use the -ErrorAction SilentlyContinue parameter.

Get-ChildItem - access to the c:windowssbs is denied

You can get the dimensions of all first-level subfolders in the desired listing. For instance, you wish to get the dimensions of all consumer profiles in the folder C:Users.

gci -force 'C:Users'-ErrorAction SilentlyContinue | ? | % %
$_.fullname, ' GB' -f ($len / 1Gb)

get user profiles size with powershell

% is an alias for the foreach-object cycle.

Let’s go on. Suppose, your process is to search out the dimensions of every listing in the basis of the system onerous drive and current the data in the handy desk kind for evaluation and capable of be sorted by the folder dimension. To do it, let’s use the Out-GridView cmdlet.

To get the details about the dimensions of directories on the drive C:, run the next PowerShell script:

$dataColl = @()
gci -force $targetfolder -ErrorAction SilentlyContinue | ? | % %
$foldername = $_.fullname
$foldersize= '' -f ($len / 1Gb)
$knowledgeObject = New-Object PSObject
Add-Member -inputObject $knowledgeObject -memberType NoticeProperty -name “foldername” -value $foldername
Add-Member -inputObject $knowledgeObject -memberType NoticeProperty -name “foldersizeGb” -value $foldersize
$dataColl += $knowledgeObject

$dataColl | Out-GridView -Title “Size of subdirectories”

get folder sizes on drive C: with posh

As you possibly can see, the graphic view of the desk ought to seem the place all folders in the basis of the system drive C: and their dimension are proven. By clicking the column header, you possibly can kind the folders by dimension.

Check Also

Configuring L2TP/IPSec VPN Connection Behind a NAT, VPN Error Code 809

Due to disabling PPTP VPN help in iOS, one in all my shoppers determined to …

Leave a Reply

Your email address will not be published. Required fields are marked *