Delete user (macOS)
0 Votes |
Description
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
27359 | |
Production - Fully Tested and Ready for Production | |
Delete user (macOS) | |
BESC | |
Internal | |
9/1/2024 12:00:00 AM | |
macos, user, delete, remove, username, mac, sysadminctl, dscl, deleteUser | |
eg2428 on 9/8/2024 2:04:02 PM | |
eg2428 on 9/8/2024 2:04:02 PM | |
289 Views / 0 Downloads | |
* Average over 0 ratings. ** Log In or Register to add your rating. |
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"Success Criteria
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"}
This action will be considered successful when all lines of the action script have completed successfully.
Sharing
Social Media: |