# Scripts to get the size of all items in a specific folder in Windows

Users can now get information about the size of files stored in a specific folder on their Windows 10/11 endpoint devices by [deploying scripts](https://www.hexnode.com/mobile-device-management/help/executing-custom-scripts-for-windows/) via Hexnode UEM console.

 Disclaimer:The sample scripts provided below are adapted from third-party open-source sites.

 

Batch script 
-------------

Batch script to get the size of all items in a specific folder

dir <enter folder path> /a /s 

   1

  dir <enter folder path> /a /s 

   

 

  

Specify the path of the folder and run the script to get a list of items in that folder with their respective file sizes (in bytes). While parameter `/a` is used to display every file, including system and hidden files, parameter `/s` lists the files in the specified directory and all the sub directories within that directory. The total size of the folder is also returned.

PowerShell script 
------------------

PowerShell script to get the size of all items in a specific folder

Get-ChildItem -path "<enter folder path>" -File -Recurse | Select-Object FullName | ForEach-Object -Process{New-Object -TypeName PSObject -Property @{Name =$\_.FullName;Size = (Get-ChildItem -path $\_.FullName -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum ).Sum/1kb}} | Select-Object Name, @{Name="Size(KB)";Expression={("{0:N2}" -f($\_.Size))}} 

   1

2

3

4

5

6

7

8

9

  Get-ChildItem -path "<enter folder path>" -File -Recurse |

Select-Object FullName |

ForEach-Object -Process{New-Object -TypeName PSObject -Property @{Name =$\_.FullName;Size = (Get-ChildItem -path $\_.FullName -Recurse -Force -ErrorAction SilentlyContinue |

Measure-Object -Property Length -Sum ).Sum/1kb}} |

Select-Object Name, @{Name="Size(KB)";Expression={("{0:N2}" -f($\_.Size))}} 

   

 

  

The script returns the name and size of all files (in KB) present in the specified folder.

 Notes:- It is recommended to manually validate the script execution on a system before executing the action in bulk.
- Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.