File Path Length >= 390

Hello everyone —

I’m in the process of migrating my users to OneDrive for Business with folder redirection and figured I’d share a quick script I made here and see if anyone has better ideas as I just threw this together.

Anyway, at my last place of work, I had issues with a OneDrive migration because of file path sizes being too large (256 was max then) and so I figured I’d nip that in the bud and search for the to be redirected folders so I can catch anyone that may cause some headaches. The max file path length now is 400, so I am looking for anything 390+ to give myself some cushion.

Our naming convention for computers is the persons username so it makes this super easy.

$users = adcomputer -filter * -searchbase "ou=workstations,dc=Company,dc=com" | ForEach-Object {$_.Name} foreach ($user in $users) { $Favorites = cmd /c dir \$userC$users$userFavorites /s /b |? {$_.length -gt 390} $Desktop = cmd /c dir \$userC$users$userDesktop /s /b |? {$_.length -gt 390} $Documents = cmd /c dir \$userC$users$userDocuments /s /b |? {$_.length -gt 390} if($Favorites.Length -ne $null){ $Favorites | Out-File c:temp$user`Favorites.txt } if($Desktop.Length -ne $null){ $Desktop | Out-File c:temp$user`Desktop.txt } if($Documents.Length -ne $null){ $Documents | Out-File c:temp$user`Documents.txt } } 

Thoughts on this? I feel like there is a cleaner way to do this, but it’s what I came up with.

submitted by /u/BitteringAgent
[link] [comments]

Leave a Reply