# The example shows how to modify an existing account in SecureAnyBox # If you want to use PowerShell commands to work with SecureAnyBox, first # install SABPowerShellModule.msi # First, we need to authenticate the user. Connect-Sab command connects to SecureAnyBox and # opens the login dialogue. # Due to security reasons, we strongly recommend not using an admin user account. # Create (or use) a user account with minimum permissions (READ and CREATE) only # for the destination Safe Box instead. $sabUrl = "http://127.0.0.1/sab" ## enter Url of SecureAnyBox $loginStatus = connect-sab $sabUrl # If the second-factor authentication is required, the set-2fa function # opens a dialogue for entering the code if ( $loginStatus.SecondFactorRequired ) { set-2fa } try{ # After the user logs in, it is necessary to get the id of account record to modify. # PowerShell commands Get-Records, Get-SafeBoxes and where-object are used to get record id # for a given record name. # When the response from the SecureAnyBox server is received, it is necessary to # check if the received id is valid and the script can continue $recordName = 'account_name' $safeBoxes = Get-SafeBoxes | Get-SafeBoxes | Where-Object { $_.Type -eq "SAFEBOX" } $recordId = $safeBoxes | Get-Records | where-object { $_.Name -like $recordName -and $_.Template -eq 'Account'} | Select-Object -expand id if ( $recordId -le 0 ) { Write-Host "Account '$recordName'not found." exit } # If multiple accounts with the same name found, it is necessary to select # which account should be modified. if ($recordId.GetType().Name -eq 'Object[]'){ Write-Host $recordId.count "accounts found." Write-Host "------------------------------------------" foreach ($id in $recordId){ Get-Record -Id $id Write-Host "------------------------------------------" } $selectedId = Read-Host "Enter id of account to modify" if ($recordId.contains($selectedId)){ $recordId = $selectedId Write-Host "`nAccount '$recordName' found. (id $recordId)`n" } else { Write-Host "`nEntered id is invalid ! `n" exit } } else{ Write-Host "Account '$recordName' found. (id $recordId)" } # Using the Get-Record command user obtains existing record from the SecureAnyBox into the $acc variable. # In the variable, it is possible to change all account record's values except the password. # To change the Password, use the Set-Password command instead. # Note: If you do not want to change any of the values, add the # character to the beginning of a specific line. $acc = Get-Record -Id $recordId $acc.Name = "account name" $acc.LoginName = "loginname" $acc.ServerAddress = "server_address" $acc.Site = "site" $acc.Description = "description" $acc.Tags.Remove('tag1') ## each tag must be added individually $acc.Tags.Add('tag2') $acc.Note = "noteline1`nnoteline2" ## use `n to add new line $acc.Launcher = "NONE" ## select one of the values : NONE, REMOTE_DESKTOP, SSH, SFTP, SCP, TELNET, FTP, RASDIAL, WINBOX # To make change in any record, we need to know the id of record and changed variables. # PowerShell Set-Record function returns the account object. If the id from returned account # object is greater than zero, then the account record modification was successful. $newRec = $acc | Set-Record -Id $recordId $accountId = $newRec.id $accountName = $newRec.Name if ( $accountId -gt 0 ) { Write-Host "Account '$accountName' modified. (id $accountId )" } } finally{ # When the connection is not needed anymore, disconnect from the SecureAnyBox server. $loginStatus = Disconnect-SAB if(! $loginStatus.Authenticated){ Write-Host "Disconnected from SecureAnyBox server" } }