Annoyingly, the
DirectoryName
property doesn't seem to work when you're sorting the results. Neither does the
Parent
property.
You'll probably need to use
Select-Object
to add a computed property to the list:
$deleteFolderList = Get-ChildItem -Path $rootFolder -Recurse -Directory -Include ( $folderNamePatterns ) | Select-Object FullName, @{n='l';e={$_.Parent.FullName.Length}} | Sort-Object -Property l
Windows PowerShell Tip of the Week | Microsoft Docs[
^]