Delete user (macOS)
Log In or Register to download the BES file, and more.

0 Votes

Description

Enter username to delete
Returns exit code 44 if supplied user is not found
Returns exit code 3 if user was not successfully deleted (typically if supplied user is the only remaining account with a secure token)

Property Details

ID27359
StatusProduction - Fully Tested and Ready for Production
TitleDelete user (macOS)
DomainBESC
SourceInternal
Source Release Date9/1/2024 12:00:00 AM
Keywordsmacos, user, delete, remove, username, mac, sysadminctl, dscl, deleteUser
Added by on 9/8/2024 2:04:02 PM
Last Modified by on 9/8/2024 2:04:02 PM
Counters 289 Views / 0 Downloads
User Rating 1 star 2 star 3 star 4 star 5 star * Average over 0 ratings. ** Log In or Register to add your rating.

Relevance

Used in 227 fixlets and 100 analyses   * Results in a true/false
Show indented relevance
mac of operating system

Actions

Action 1 (default)

Action Link Click here to deploy this action.
Script Type BigFix Action Script
parameter "mainSWDLogFolder" = "{parent folder of client folder of current site}/__Global/SWDDeployData"
folder create "{parameter "mainSWDLogFolder"}"
parameter "logFile" = "SWD_DeploymentResults.log"

parameter "scriptName" = "hitlist.sh"

wait sh -c "echo '' >> '{parameter "mainSWDLogFolder"}/{parameter "logFile"}'"
wait sh -c "echo $(date +%Y_%m_%d' '%T) >> '{parameter "mainSWDLogFolder"}/{parameter "logFile"}'"
wait sh -c "echo Action ID: {id of active action} >> '{parameter "mainSWDLogFolder"}/{parameter "logFile"}'"

action parameter query "user" with description "Enter username to delete"

delete __createfile
delete "{parameter "scriptName"}"
createfile until _EOF_
#!/bin/zsh

toDeleteUser="{parameter "user"}"

if id "$toDeleteUser" >/dev/null 2>&1; then
    echo "User $toDeleteUser found" >> '{parameter "mainSWDLogFolder"}/{parameter "logFile"}'
else
    echo "User $toDeleteUser not found" >> '{parameter "mainSWDLogFolder"}/{parameter "logFile"}'
    exit 44
fi

sysadminctl -deleteUser "$toDeleteUser" >> '{parameter "mainSWDLogFolder"}/{parameter "logFile"}'
sleep 5

if id "$toDeleteUser" >/dev/null 2>&1; then
    echo "User $toDeleteUser still found, not successfully deleted" >> '{parameter "mainSWDLogFolder"}/{parameter "logFile"}'
    exit 3
else
    echo "User $toDeleteUser no longer exists" >> '{parameter "mainSWDLogFolder"}/{parameter "logFile"}'
fi
exit 0
_EOF_
copy "__createfile" "{parameter "scriptName"}"
wait chmod +x "{parameter "scriptName"}"
wait /bin/zsh "{parameter "scriptName"}"
parameter "exitCode" = "{exit code of action}"
delete __createfile
delete "{parameter "scriptName"}"

wait sh -c "echo Return Code: {parameter "exitCode"} >> '{parameter "mainSWDLogFolder"}/{parameter "logFile"}'"

if {parameter "exitCode" != "0"}
exit {parameter "exitCode"}
endif

exit {parameter "exitCode"}
Success Criteria

This action will be considered successful when all lines of the action script have completed successfully.


Sharing

Social Media:
Share this page on Yammer

Comments

Log In or Register to leave comments!