Skip to content

$cs.UsrMgr_CreateLocalUser

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.

$cs.UsrMgr_CreateLocalUser(string userName, string fullName, string password, string description = “”, bool passwordNeverExpire = true, bool userCannotChangePwd = false)

The name of the local user account to create.

The full name of the user.

The password for the account, in clear text.

Description for the user account. Defaults to an empty string.

Sets whether the password never expires. Defaults to $true.

Sets whether the user is prevented from changing their own password. Defaults to $false.

None.

Create a local user with the default settings (password never expires, user can change it):

Terminal window
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:

Terminal window
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:

Terminal window
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)
}

$cs.UsrMgr_ExistLocalUserAccount $cs.UsrMgr_DeleteLocalUserAccount $cs.UsrMgr_ChangePassword