Fixing the My Documents folder problem en mass

0
Fixing the My Documents folder problem

Rename users My Documents to Documents so that Redirected folders works correctly.

It is best to run this script first and the other script lower down second in my experience. The process should be –

  1. Fix any incorrectly named My Documents folders to Documents
  2. Move any Documents not in actual Documents folders into new Documents folders
  3. Use NTFSFix to set perms

We often find that the user Documents folders are named My Documents which for GPO Folder redirection isn’t correct as the system will look for Documents to we often have to run the below to rename My Documents to Documents en-mass for all users.

clear
$InputFolder = Read-Host "PATH"
$FolderPath = Get-ChildItem -Directory -Path $InputFolder
$Output = @()
ForEach ($Folder in $FolderPath) {
	$BadPath = $Folder.FullName + "\My Documents"
	$GoodPath = $Folder.FullName + "\Documents"
    $ValidPath = Test-path $BadPath
	
	If ($ValidPath -eq $false) {
	Write-Host "$Folder - GO for Launch"
	} Else {
	Write-Host "$Folder - Houston, we have a problem, renaming My Documents to Documents!"
	move $BadPath $GoodPath
	}

}
	Write-Host "All folders have been moved - We are GO for Launch"

Move users Documents to a Documents folders instead of the root of the folder

Fixing the My Documents folder problem has often been a pain as we have this problem over and over during migration when you find that a user has been setup in such a way that their My Docs path is essentially pointing to the root folder of their folder on the server; for example an invalid path would be –

D:\Users\Student\Intake 2019\JBloggs\my powerpoint.pptx

Where as we want/need all users to be setup as below –

D:\Users\Student\Intake 2019\JBloggs\Documents\my powerpoint.pptx

This is due to the great way in which Windows 10 renames Documents folders to My Documents making it impossible (not actually impossible) to see who the folder belongs to.

In order to resolve the issue I use the script below which checks for the presence of a Documents folder and if one doesn’t exist creates one and moved the docs over.

Simply run the script from a PowerShell Admin console and point it to the root of your users directory; for example D:\Users\Student\Intake 2019 it will then recourse through each subfolder and rename as required.

This is useful for when the users have been setup with their docs at the root of their folders and the user folder shows as being renamed.

clear
$InputFolder = Read-Host "PATH"
$FolderPath = Get-ChildItem -Directory -Path $InputFolder
$Output = @()
ForEach ($Folder in $FolderPath) {
	$FullPath = $Folder.FullName + "\Documents"
    $ValidPath = Test-path $FullPath
	
	If ($ValidPath -eq $True) {
	Write-Host "$Folder - GO for Launch"
	} Else {
	Write-Host "$Folder - Houston, we have a problem, moving docs folder now!"
	robocopy $Folder.FullName $FullPath /E /R:1 /W:1 /XD $FullPath /MOVE
	}

}
	Write-Host "All folders have been moved - We are GO for Launch"

Found priceless insights in this blog? Support the author’s creativity – buy them a coffee!

Leave a Reply

Your email address will not be published. Required fields are marked *