Skip to main content

We are trying to remove an old local account that is on most of our windows computers.  The code removed the account when I ran it locally but not when I run it through automox.

 

# Delete a local account named "tommyboy" 
$AccountName = "tommyboy"

# Check if the account exists
if (Get-LocalUser -Name $AccountName -ErrorAction SilentlyContinue) {
# Forcefully delete the account
Remove-LocalUser -Name $AccountName -Force
Write-Host "The account '$AccountName' has been deleted successfully."
} else {
Write-Host "The account '$AccountName' does not exist."
}

 

Hi Slammert,

This is a situation where get-localuser is not available for 32-bit powershell

 

 

I was able to get this pieced together which worked, using 32-bit available commands:

 

# ======================
# Otto AI Generated Code
# ======================
# Define the username of the account you want to delete
$username = "delete-me" # Replace with the actual username

# Check if the user exists using net user command
$userExists = net user | Select-String -Pattern $username

if ($userExists) {
# Remove the user account using net user command
net user $username /delete
Write-Host "User account '$username' has been deleted."
} else {
Write-Host "User account '$username' does not exist."
}

 


Thanks Mark!!!

 


Reply