Fixing the My Documents folder problem en mass

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.

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"

We also often find that the user Documents are is 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"

If you found this article helpful, would you consider buying me a Coffee?