Category filter

Script to remotely Create User Accounts on macOS devices

With the help of the scripts provided below, user management on macOS can be done with ease. Creating new user accounts, assigning appropriate roles, or even removing existing user accounts can be accomplished by the IT admin utilizing the “Execute Custom Script” feature provided by Hexnode UEM.

Scripting language – Bash

File extension – .sh

Disclaimer:


The sample scripts provided below are adapted from third-party open-source sites.

Create an Admin User account

The “export” command is used to set the “PATH” variable as an environment variable. Environment variables are special variables that contain information about your login session. The directories “/usr/bin:/bin:/usr/sbin:/sbin” contain essential system binaries and commands used by the operating system. The “PATH” variable specifies the directories where the system looks for executable files when a command is entered. In this script, it ensures that the “sysadminctl” command can be found and executed since it is part of the system administration tools.

The “sysadminctl” command is used for managing user accounts from the command line. The “-addUser” option is used within “sysadminctl” to create a new user on macOS. “-admin” parameter grants administrative privileges to the user account.

Create a Standard User account

The administrator can provide the username and password of the new account against the USERNAME and PASSWORD fields respective. The display name and password hint of the new account can be specified against the FULLNAME and PASSWORDHINT fields.The created user assumes the role of a standard user as the “-admin” parameter is not included in the “sysadminctl” command.

What happens at the device end?

A new user will be created, either as an admin or standard user, based on the configuration in the script. This user account will appear in System Settings/System Preferences > Users & Groups and will be able to log in using the password provided in the script.

An admin user will be created remotely on the device

Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository