# The example shows how to modify an existing credit card 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 credit card 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 = 'credit_card_name' $safeBoxes = Get-SafeBoxes | Get-SafeBoxes | Where-Object { $_.Type -eq "SAFEBOX" } $recordId = $safeBoxes | Get-Records | where-object { $_.Name -like $recordName -and $_.Template -eq 'Ccard'} | Select-Object -expand id if ( $recordId -le 0 ) { Write-Host "Credit card '$recordName'not found." exit } # If multiple credit cards with the same name found, it is necessary to select # which credit card should be modified. if ($recordId.GetType().Name -eq 'Object[]'){ Write-Host $recordId.count "credit cards found." Write-Host "------------------------------------------" foreach ($id in $recordId){ Get-Record -Id $id Write-Host "------------------------------------------" } $selectId = Read-Host "Enter id of credit card to modify" if ($recordId.contains($selectId)){ $recordId = $selectId Write-Host "`nCredit card '$recordName' found. (id $recordId)`n" } else { Write-Host "`nEntered id is invalid ! `n" exit } } else{ Write-Host "Credit card '$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 credit card 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. $ccard = Get-Record -Id $recordId #$ccard.Name = "credit card name" $ccard.Description = "description" $ccard.Tags.Remove('tag1') $ccard.Tags.Add('tag2') $ccard.Note = "noteline1`nnoteline2" ## use `n to add new line $ccard.Attributes.number = "8745 5896 1752 5963 4812" $ccard.Attributes.expiration = "2025-08-31T00:00:00.000Z" $ccard.Attributes.'cvv' = "111" $ccard.Attributes.pin = "1234" $ccard.Attributes.'sec-note' = "secretnoteline1`nline2" ## use `n to add new line # To make change in any record, we need to know the id of record and changed variables. # PowerShell Set-Record function returns the credit card object. If the id from returned credit card # object is greater than zero, then the credit card record modification was successful. $newRec = $acc | Set-Record -Id $recordId $creditCardId = $newRec.id $creditCardName = $newRec.Name if ( $creditCardId -gt 0 ) { Write-Host "Credit card '$creditCardName' modified. (id $creditCardId )" } } 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" } }