#Import CSV-file with the following headers: old,new,sid
$users = Import-Csv -Path "\\domain.local\netlogon\renamed-users.csv"
#Determine OS-version and set profilepath variable
$OS = Get-WmiObject Win32_OperatingSystem
switch -wildcard ($OS.Version)
{
"5.1*" {$profilepath = "C:\Documents and Settings\"}
"6.0*" {$profilepath = "C:\Users\"}
"6.1*" {$profilepath = "C:\Users\"}
}
foreach ($user in $users) {
#Check if SID is listed in the ProfileList registry key
if ($user.sid) {
#Rename profilepath in registry
if (Test-Path ("HKLM:\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\"+$user.sid)) {
Set-ItemProperty -Path ("HKLM:\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\"+$user.sid) -Name "ProfileImagePath" -Value ($profilepath+$user.new)
#Check if profilepath exist
if (Test-Path ($profilepath+$user.old)) {
#Rename profile folder
Rename-Item -Path ($profilepath+$user.old) -NewName ($profilepath+$user.new)
}
}
}
}