Category filter

Script to delete local user accounts on Windows

You might have configured multiple user accounts on your Windows devices in a shared-device environment. However, over time, there can be one or more user accounts that are not being used. In such scenarios, you can delete those user accounts as they are no longer necessary. Using Hexnode, you can remotely run custom scripts on your Windows devices to delete any specific user account or all user accounts except the specified ones.

Disclaimer:

The Sample Scripts provided below are adapted from third-party Open-Source sites.

Batch script to delete a specific user account

Specify the username of the account to be deleted in the Arguments space when executing the above script from the Hexnode portal.

PowerShell script to delete a specific user account

Specify the username of the account to be deleted in the Arguments space when executing the script via the Hexnode portal.

PowerShell script to delete all user accounts except specific user accounts

You can use the above script to delete all the user accounts on the device other than the required ones. Specify the username of the accounts to be retained on the device corresponding to the $UserList variable. You can specify multiple user accounts separated by commas.

For example, the below script will delete all the user accounts except DefaultAccount, Guest, IEUser and sshd:

You can run the Get-LocalUser command to get a list of all the user accounts on the device before deciding on the user accounts to be deleted.

Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository