Measure Folder size containing SymbolicLink

%3CLINGO-SUB%20id%3D%22lingo-sub-2401832%22%20slang%3D%22en-US%22%3EMeasure%20Folder%20size%20containing%20SymbolicLink%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2401832%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3EI%20have%20the%20fallowing%20problem.%20I%20want%20to%20get%20the%20size%20of%20folders%20but%20some%20of%20them%20have%20subfolders%20that%20are%20SymbolicLink%20to%20other%20folders.%20How%20do%20I%20easily%20exclude%20them%3F%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3Efunction%20GetFolderSize(%24path)%7B%3C%2FP%3E%3CP%3E%24total%20%3D%20(Get-ChildItem%20%24path%20-Recurse%20-Force%20-ErrorAction%20SilentlyContinue%20%7C%20Measure-Object%20-Property%20length%20-Sum%20-ErrorAction%20SilentlyContinue).Sum%3C%2FP%3E%3CP%3Eif%20(-not(%24total))%20%7B%20%24total%20%3D%200%20%7D%3C%2FP%3E%3CP%3E%24total%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EComplicated%20way%20i%20was%20thinking%20to%20check%20all%20the%20folders%2C%20and%20calculate%20only%20the%20ones%20that%20are%20not%20SymbolicLink.%20But%20this%20will%20not%20be%20a%20easy%20way.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%2C%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2401832%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2419736%22%20slang%3D%22en-US%22%3ERe%3A%20Measure%20Folder%20size%20containing%20SymbolicLink%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2419736%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F201310%22%20target%3D%22_blank%22%3E%40Adrian%20Chirtoc%3C%2FA%3E%26nbsp%3BYou%20will%20need%20to%20add%20the%20following%20filter%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3Ewhere%20%7B%24_.LinkType%20-notlike%20%22SymbolicLink%22%7D%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

Hello,

I have the fallowing problem. I want to get the size of folders but some of them have subfolders that are SymbolicLink to other folders. How do I easily exclude them?

function GetFolderSize($path){

$total = (Get-ChildItem $path -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property length -Sum -ErrorAction SilentlyContinue).Sum

if (-not($total)) { $total = 0 }

$total

}

 

Complicated way i was thinking to check all the folders, and calculate only the ones that are not SymbolicLink. But this will not be a easy way.

 

Thank you,

3 Replies

@Adrian Chirtoc You will need to add the following filter 

where {$_.LinkType -notlike "SymbolicLink"}

This at me did not skip the files inside the folder that had the SymolicLink as they do not have this property. Only the folder has it.

Can you share the PowerShell Property members for the folder and SL.