$cs.UsrMgr_CreateLocalUser
Description
Section titled “Description”Creates a local user account. After creation, the function verifies that the account actually exists before returning. Throws an ArgumentException on bad arguments, or another exception if creation fails.
Syntax
Section titled “Syntax”$cs.UsrMgr_CreateLocalUser(string userName, string fullName, string password, string description = “”, bool passwordNeverExpire = true, bool userCannotChangePwd = false)
Parameters
Section titled “Parameters”userName (String)
Section titled “userName (String)”The name of the local user account to create.
fullName (String)
Section titled “fullName (String)”The full name of the user.
password (String)
Section titled “password (String)”The password for the account, in clear text.
description (String)
Section titled “description (String)”Description for the user account. Defaults to an empty string.
passwordNeverExpire (Boolean)
Section titled “passwordNeverExpire (Boolean)”Sets whether the password never expires. Defaults to $true.
userCannotChangePwd (Boolean)
Section titled “userCannotChangePwd (Boolean)”Sets whether the user is prevented from changing their own password. Defaults to $false.
Return value
Section titled “Return value”None.
Example
Section titled “Example”Create a local user with the default settings (password never expires, user can change it):
if (-not $cs.UsrMgr_ExistLocalUserAccount('capauser')) { $cs.Job_WriteLog("Creating local user capauser") $cs.UsrMgr_CreateLocalUser('capauser', 'Capa User', 'SuperSecretPassw0rd!')}Create a dedicated service account with a description and a never-expiring password, so scheduled tasks and services relying on it don’t break after a password expiry policy kicks in:
if (-not $cs.UsrMgr_ExistLocalUserAccount('svc_capaagent')) { $cs.Job_WriteLog("Creating service account svc_capaagent") $cs.UsrMgr_CreateLocalUser('svc_capaagent', 'Capa Agent Service Account', 'SuperSecretPassw0rd!', 'Runs the Capa Agent Windows service', $true)}Create a kiosk-style shared account where the logged-on user must not be able to change the password:
if (-not $cs.UsrMgr_ExistLocalUserAccount('kioskuser')) { $cs.Job_WriteLog("Creating locked-down kiosk account kioskuser") $cs.UsrMgr_CreateLocalUser('kioskuser', 'Kiosk User', 'SuperSecretPassw0rd!', 'Shared kiosk account', $true, $true)}Related functions
Section titled “Related functions”$cs.UsrMgr_ExistLocalUserAccount $cs.UsrMgr_DeleteLocalUserAccount $cs.UsrMgr_ChangePassword