Skip to content

Instantly share code, notes, and snippets.

@libotti
Created July 16, 2022 07:56
Show Gist options
  • Save libotti/873a11f35ab0288513751ca2365bc4eb to your computer and use it in GitHub Desktop.
Save libotti/873a11f35ab0288513751ca2365bc4eb to your computer and use it in GitHub Desktop.
Move all windows userprofiles from C:\USERS to D:\Users
$ProfilePaths = Get-ChildItem "REGISTRY::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" |
Where-Object {$_.Name -match "^S-1-5-21*"} |
Select-Object -ExpandProperty Name -Skip 1 | Foreach {
(Get-ItemProperty "REGISTRY::$($_)" -Name "ProfileImagePath").ProfileImagePath
}
$ProfilePaths = $ProfilePaths | Where-Object {$_ -ne "C:\Users\$($env:Username)"}
$ProfilePaths | Foreach {
$Current = "$_"
$Move = $_ -replace "^C:","D:"
Move-Item -Path "$Current" -Destination "$Move"
$User = New-Object System.Security.Principal.NTAccount("$(Split-Path "$Current" -Leaf)")
$SID = $User.Translate([System.Security.Principal.SecurityIdentifier])
Set-ItemProperty "REGISTRY::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$($SID.Value)" -Name "ProfileImagePath" -Value "$Move"
}
Move-Item -Path "C:\Users\Default" -Destination "D:\Users\Default"
Set-ItemProperty "REGISTRY::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" -Name "Default" -Value "D:\Users\Default"
Move-Item -Path "C:\Users\Public" -Destination "D:\Users\Public"
Set-ItemProperty "REGISTRY::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" -Name "Public" -Value "D:\Users\Public"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment