Search code examples
powershellpowershell-2.0user-accounts

Powershells script to Re-name Local Guest & Administrator Account?


Does anyone have a PowerShell script that will rename a local user account (Guest & Administrator)? I am looking for something along the lines of what i have below or something close enough.

function Set-NewUserName{
    param($OldUserName, $NewUserName)
    #Implement Black Magic to change username.
}

Solution

  • You can use WMI to do this.

    $user = Get-WMIObject Win32_UserAccount -Filter "Name='$oldName'"
    $result = $user.Rename($newName)
    
    if ($result.ReturnValue -eq 0) {
    return $user
    # you may just print a message here
    }