Change Username and full name.
  • 03 Nov 2023
  • 1 Minute to read
  • PDF

Change Username and full name.

  • PDF

Article summary

The following PowerShell script helps the IT Admins change the username and full name of the users on the managed Windows devices.

  1. Create a file on your desktop, for example, To_change_username_and_fullname.ps1 and open it in a text editor like notepad++
  2. Copy the contents below to the file or click here to download the file.
    Shell
    # Define the old and new usernames and full names
    $oldUsername = "old_username"
    $newUsername = "new_username"
    $newFullName = "new_fullname"
    
    # Check if the old username exists
    if (Get-WmiObject Win32_UserAccount | Where-Object { $_.Name -eq $oldUsername }) {
        # Rename the user account (username)
        Rename-LocalUser -Name $oldUsername -NewName $newUsername
    
        # Modify the user's full name
        Get-WmiObject Win32_UserAccount -Filter "Name='$newUsername'" | ForEach-Object {
            $_.FullName = $newFullName
            $_.Put()
        }
    
        Write-Host "User account $oldUsername has been renamed to $newUsername, and the full name has been updated to $newFullName."
    } else {
        Write-Host "User account $oldUsername not found."
    }
    1. Replace the data in the script as shown below with the correct new usernames and new full name, for example:  
      Shell
      $oldUsername = "Jinny"
      $newUsername = "Liza"
      $newFullName = "Liza"

  3. Follow our guide to upload & publish the PowerShell script using Scalefusion Dashboard.
  4. Once the script is successfully executed, you will be able to see the status of the same in the View Status report on the Scalefusion dashboard.
Please note that to use the PowerShell scripts, the Scalefusion MDM Agent Application must be installed on the device(s). Please follow our guideto publish and install the Scalefusion MDM Agent Application.

Notes:
  1. The scripts and their contents are sourced from various albeit authenticated Microsoft sources and forums.
  2. Please validate the scripts on a test machine before deploying them on all your managed devices.
  3. Scalefusion has tested these scripts, however, Scalefusion will not be responsible for any loss of data or system malfunction that may arise due to the incorrect usage of these scripts.




Was this article helpful?