# $cs.UsrMgr_ChangePassword

> Changes the password of a local user account. If the specified user does not exist, the function returns silently without error.

Source: https://docs.capaone.com/capainstaller/powerpacks/cs-usrmgr-changepassword/  
Product: CapaInstaller — a separate CapaSystems product; do not apply this page to any other.

### Description

Changes the password of a local user account. If the specified user does not exist, the function returns silently without error. Throws an exception on other failures.

### Syntax

$cs.UsrMgr_ChangePassword(string userName, string password)

### Parameters

#### userName (String)

Name of the local user whose password will be changed. If the user does not exist, no error is raised.

#### password (String)

The new password, in clear text.

### Return value

None.

### Example

**PowerShell**

Rotate a local service account's password as part of an application upgrade:

```powershell
if ($cs.UsrMgr_ExistLocalUserAccount('administrator')) {
  $cs.Job_WriteLog("Changing password for administrator")
  $cs.UsrMgr_ChangePassword('administrator', 'VerySuperSecretPassw0rd!')
}
```

Generate a random password, store it in a variable, and apply it to a service account before restarting the service that runs under it:

```powershell
Add-Type -AssemblyName System.Web
$newPassword = [System.Web.Security.Membership]::GeneratePassword(16, 4)

if ($cs.UsrMgr_ExistLocalUserAccount('svc_capaagent')) {
  $cs.Job_WriteLog("Rotating password for svc_capaagent")
  $cs.UsrMgr_ChangePassword('svc_capaagent', $newPassword)
  Set-Service -Name 'CapaAgentService' -Credential (New-Object System.Management.Automation.PSCredential('svc_capaagent', (ConvertTo-SecureString $newPassword -AsPlainText -Force)))
  Restart-Service -Name 'CapaAgentService' -Force
}
```

### Related functions

[$cs.UsrMgr_CreateLocalUser](/capainstaller/powerpacks/cs-usrmgr-createlocaluser/) [$cs.UsrMgr_ExistLocalUserAccount](/capainstaller/powerpacks/cs-usrmgr-existlocaluseraccount/)
