$cs.UsrMgr_ExistLocalUserAccount
Description
Section titled “Description”Checks whether a local user account exists. Accepts either a plain user name or a SID.
Syntax
Section titled “Syntax”$cs.UsrMgr_ExistLocalUserAccount(string userName)
Parameters
Section titled “Parameters”userName (String)
Section titled “userName (String)”Name or SID of the local user account to check for.
Return value
Section titled “Return value”[bool] $true if the local user account exists, otherwise $false.
Example
Section titled “Example”Gate a password change so it only runs when the account is present:
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:
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")}Related functions
Section titled “Related functions”$cs.UsrMgr_CreateLocalUser $cs.UsrMgr_DeleteLocalUserAccount $cs.UsrMgr_ChangePassword