Delete directory regardless of 260 char limit

后端 未结 17 1764
無奈伤痛
無奈伤痛 2020-12-08 02:03

I\'m writing a simple script to delete USMT migration folders after a certain amount of days:

## Server List ##
$servers = \"Delorean\",\"Adelaide\",\"Brisba         


        
17条回答
  •  庸人自扰
    2020-12-08 02:30

    This is getting old but I recently had to work around it again. I ended up using 'subst' as it didn't require any other modules or functions be available on the PC this was running from. A little more portable.

    Basically find a spare drive letter, 'subst' the long path to that letter, then use that as the base for GCI.

    Only limitation is that the $_.fullname and other properties will report the drive letter as the root path.

    Seems to work ok:

    $location = \\path\to\long\
    $driveLetter = ls function:[d-z]: -n | ?{ !(test-path $_) } | random
    
    subst $driveLetter $location
    sleep 1
    Push-Location $driveLetter -ErrorAction SilentlyContinue
    Get-ChildItem -Recurse
    
    subst $driveLetter /D
    

    That command is obviously not to delete files but can be substituted.

提交回复
热议问题