$cs.UsrMgr_DeleteLocalUserAccount
Description
Section titled “Description”Deletes a local user account. Accepts either a plain user name or a SID. If the user does not exist, the function returns silently without error.
Syntax
Section titled “Syntax”$cs.UsrMgr_DeleteLocalUserAccount(string userName)
Parameters
Section titled “Parameters”userName (String)
Section titled “userName (String)”The local user account to delete. Can be a plain user name or a SID. If the account does not exist, no error is raised.
Return value
Section titled “Return value”None.
Example
Section titled “Example”if ($cs.UsrMgr_ExistLocalUserAccount('capauser')) { $cs.Job_WriteLog("Removing local user capauser") $cs.UsrMgr_DeleteLocalUserAccount('capauser') # or by SID: $cs.UsrMgr_DeleteLocalUserAccount('S-1-5-21-3559337461-1037079836-4233830826-1109')}Clean up a temporary account created during install, as part of PostUninstall:
function PostUninstall { if ($cs.UsrMgr_ExistLocalUserAccount('capa_tempinstall')) { $cs.Job_WriteLog("Removing temporary install account capa_tempinstall") $cs.UsrMgr_DeleteLocalUserAccount('capa_tempinstall') }}Delete an account by SID when the account name may have been changed or localized after creation:
$accountSid = 'S-1-5-21-3559337461-1037079836-4233830826-1109'if ($cs.UsrMgr_ExistLocalUserAccount($accountSid)) { $cs.Job_WriteLog("Removing local account with SID $accountSid") $cs.UsrMgr_DeleteLocalUserAccount($accountSid)}