NetNXT Logo

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.

November 7, 2025
2 min read
ByNetNXT
On this page
Share this article

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

  1. Login to JumpCloud Admin Console
  2. Go to Commands → + Add New Command
  3. Select macOS
  4. Paste this script in the Command section
  5. (Replace username_to_retain with 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
  1. Run once with armed=false → confirm output
  2. When verified, set armed=true to actually delete disabled users

Step 2 — Delete unwanted user profiles on Windows

  1. In JumpCloud → Go to Commands → + Add New Command
  2. Check Windows
  3. Paste this PowerShell script
  4. (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
    }
}
  1. Run the command
  2. 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 expert
Was this article helpful?

Stay 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

Have a question about this guide?

Our security engineers read every message.

Contact us