Deleting Unwanted User Profiles from macOS and Windows using JumpCloud
Use JumpCloud Commands to safely remove unwanted user profiles from macOS and Windows devices. Preserve required users, test before deletion, then execute removal scripts across your fleet for system hygiene.
On this page
Purpose
Remove unwanted or suspended user profiles on macOS and Windows endpoints directly via JumpCloud Commands, while preserving required users.
Prerequisites
- JumpCloud admin access
- Devices must be Active (commands won’t execute on Inactive machines)
- Username(s) to preserve must be identified before running scripts
- Understand risk: deletion is permanent
Step-by-Step Instructions
Step 1 — Delete unwanted user profiles on macOS
- Login to JumpCloud Admin Console
- Go to Commands → + Add New Command
- Select macOS
- Paste this script in the Command section
- (Replace
username_to_retainwith the user you want to keep enabled)
#!/bin/bash
armed=false
target_user="username_to_retain"
sudo dscl . -delete "/Users/$target_user" AuthenticationAuthority ";DisabledUser;"
IFS=$'\n'
for x in $(dscl . -list /Users); do
if dscl . -read "/Users/$x/" | grep -q DisabledUser; then
if [[ ! "$x" =~ "_jumpcloudserviceaccount" ]]; then
if [[ "$armed" == true ]]; then
sudo sysadminctl -deleteUser "$x"
fi
fi
fi
done
exit 0
- Run once with
armed=false→ confirm output - When verified, set
armed=trueto actually delete disabled users
Step 2 — Delete unwanted user profiles on Windows
- In JumpCloud → Go to Commands → + Add New Command
- Check Windows
- Paste this PowerShell script
- (Replace
"user name"with user(s) to keep)
$usersToKeep = @("user name")
$allUsers = Get-LocalUser
foreach ($user in $allUsers) {
if ($usersToKeep -notcontains $user.Name) {
Disable-LocalUser -Name $user.Name
Remove-LocalUser -Name $user.Name
}
}
- Run the command
- Check Results → verify devices executed scripts successfully
Expected Result / Validation
- macOS and Windows machines only retain the usernames you whitelisted
- All other local users that were disabled or not allowed are deleted
- You see deletion events in JumpCloud Commands → Results
FAQs
Q1. Will this delete JumpCloud-managed accounts as well?
Only if you remove them from the “users to keep” list. Make sure you list the usernames that must remain. The script deletes all others.
Q2. Should I run this directly with delete enabled?
No. Always run first with:
- mac →
armed=false - windows → test with a small batch
Then only switch to “true” mode or allow delete when you are 100% sure.
Q3. Does this work on inactive / offline devices?
No. JumpCloud Commands execute only when the device is online & active.
Q4. What if I want to preserve multiple users?
You can add multiple usernames in the $usersToKeep array (Windows) or change target_user logic (mac). The script supports multiple preserve accounts.
Need help securing your environment?
Talk to a NetNXT security expertStay ahead of the next vulnerability
New KB guides, threat advisories and hardening playbooks from NetNXT's security team — straight to your inbox.
NetNXT will handle your data pursuant to its Privacy Policy.
Like this guide? Join our team.
NetNXT builds security for how modern enterprises actually run.
View open roles