Background

When renaming a few hundred Active Directory usernames there was a need to also update the name of the local profile folders on client computers to reflect the new username.
The profiles would work using the old username, however, the request was to rename them.

Since the clients consists of a mix of Windows XP, Windows Vista and Windows 7, we plan to use either Kix or VBScript to make the necessary changes.

A csv-file with a list of all affected users are available to the script, containing the old username, the new username and the users` SID.

The script

Since PowerShell is what I know the best when it comes to scripting, I`ve written a sample PowerShell-script to show what I want to accomplish.

I would like to get some guidance on how to convert this script to Kix.
 Code:
#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)
}

}

}

}



Edited by Jan_Egil_Ring (2010-09-01 09:40 PM)