Skip to content

$cs.UsrMgr_ExistLocalUserAccount

Checks whether a local user account exists. Accepts either a plain user name or a SID.

$cs.UsrMgr_ExistLocalUserAccount(string userName)

Name or SID of the local user account to check for.

[bool] $true if the local user account exists, otherwise $false.

Gate a password change so it only runs when the account is present:

Terminal window
if ($cs.UsrMgr_ExistLocalUserAccount('capauser')) {
$cs.Job_WriteLog("capauser exists, updating password")
$cs.UsrMgr_ChangePassword('capauser', 'SecretPassw0rd')
}

Gate account creation during install so the PowerPack can be re-run safely without recreating or resetting an existing account:

Terminal window
if (-not $cs.UsrMgr_ExistLocalUserAccount('svc_capaagent')) {
$cs.Job_WriteLog("svc_capaagent does not exist yet, creating it")
$cs.UsrMgr_CreateLocalUser('svc_capaagent', 'Capa Agent Service Account', 'SuperSecretPassw0rd!')
} else {
$cs.Job_WriteLog("svc_capaagent already exists, skipping creation")
}

$cs.UsrMgr_CreateLocalUser $cs.UsrMgr_DeleteLocalUserAccount $cs.UsrMgr_ChangePassword