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."
}