top of page

PowerShell - Get folder sizes by UNC

  • Writer: Jon Boyette
    Jon Boyette
  • Jan 10, 2022
  • 1 min read

Save as a .ps1 or paste, enter UNC share OR Drive$ by \\server\drive$ name to get all folder sizes recursive, outputs to C:\temp\ServerShareSizesDiscovered.csv


$folder = '\\servername\sharename'


$DirUseArray = @()

# Get a list of first level sub-folders

$firstLevel = Get-ChildItem $folder -directory

$firstLevel | foreach {

Echo "Reading $_"

# Read the size of this folder and all its sub folders.

$size = (Get-ChildItem $folder\$_\* -recurse) | measure-object -property length -sum | Select-Object -expand sum

# Convert from Bytes to GiB and round to 2 decimal places

$size = [math]::Round($(0 + $size /1GB),2)

Echo $size

# Add to an array

$DirUseArray += New-Object PsObject -property @{

'Folder' = $_

'Size (GB)' = $size

}

}

$DirUseArray | Export-Csv -path C:\temp\ServerShareSizesDiscovered.csv -NoTypeInformation




 
 
 

Recent Posts

See All
PowerShell - List All Domain SPNs

Save as same List_ALL_SPNs.ps1 or similar, this LDap calls the Domain for all Service Principal names and accounts related #Build LDAP...

 
 
 
PowerShell - Start-Monitoring

This is a great script used to Monitor and Email if a server is up or down, once ran, and smtp and from address is set, then run:...

 
 
 

Comments


Post: Blog2 Post
  • Facebook
  • Twitter
  • LinkedIn

©2022 by Boyette Technical Services. Proudly created with Wix.com

bottom of page