First off I would like to thank you guys for taking the time to help novice users like myself. I have been doing powershell for about 4 weeks now. I have read Learn PowerShell in a month of Lunches, Learn Powershell Tool making in a month of lunches, Windows Powershell Best Practices and Windows Powershell cookbook. I have taken 3 MVA courses by Jeffrey Snover and Jason Helmick. Those guys are awesome and well spoken. they directed me to this site in one of there courses. Anyway I just wanted to introduce myself and thank you in advance for having patience with me.
here is my latest script it fixes an issue we have with folder redirection. during the process of folder redirection during boot up the computer starts to move the files from the local user folders to the network equivalent some user have files at the threshold of the character limitation what happens when it gets to this issue is everything stops and the system leaves half of there files on the redirected file server and half on the users profile.
To fix this I wrote a script when launched on the users machine retrieves the redirected path from the registry, and the path of each of the stuck user files combines them the way they would be if sent to the file server. Then it gets the length of the string if it exceeds the maximum length it builds the folder structure on root of c:\fldrrdr and moved the offending files while creating a log file of the files moved. it also makes a log file of any files we have in our filter.
Here is the code if anyone sees any mistakes or a simpler way to do it please let me know I love to learn new things.
#requires -Version 3 Set-StrictMode -Version Latest set-location $env:USERPROFILE [int]$maxpathlength = 255 $paths = ("Favorites" , "Documents" , "Desktop") if(!(test-path c:\FLDRRDR)){MD c:\FLDRRDR} # Setting Folder Redirection Variables $frd = Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders' $remotepath=($frd.desktop).replace("\Desktop","") # Finds all files in the user directory that violates the charater limitation then moves the files to c:\FLDRRDR retaining the folder structure. Foreach($path in $paths){ if(test-path $path){ $files = Get-ChildItem -Path $path -Recurse Foreach($file in $files){ $userfile = ($file.FullName).Replace("$env:USERPROFILE","") $newdir = ($userfile).Replace($($file.Name) , "") if($file.FullName -like "*.pst" -or $file.FullName -like "*.ost" -or $file.FullName -like "*.oft" -or $file.FullName -like "*.pab" -or $file.FullName -like "*.msg"){$file.FullName | Out-File c:\Long-File-Check\Outlook-Files.txt -Append} if($remotepath.Length + $userfile.Length -gt $maxpathlength) { $file.FullName | Out-File c:\FLDRRDR\Long-File-Names-Log.txt -Append if(!(test-path "C:\FLDRRDR$($newdir)" )){MD "C:\FLDRRDR$($newdir)"} if(test-path "C:\FLDRRDR$($newdir)" ){move-item -Path "$($file.FullName)" -Destination "C:\FLDRRDR$($newdir)"} } } } }