# The example shows how to add a credit card to an existing Safe Box 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 destination Safe Box, # to where the credit card will create. # PowerShell commands get-safeboxes and where-object are used to get Safe Box id # for a given Safe Box 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 $safeBoxName = 'safeboxName' $safeBoxId = get-safeboxes | where-object { $_.name -like $safeBoxName -and $_.Type -eq 'SAFEBOX' } | Select-Object -expand id if ( $safeBoxId -le 0 ) { Write-Host "Safe Box' $safeBoxName 'not found." exit } Write-Host "Safe Box '$safeBoxName' found. (id $safeBoxId)" # Set the name and login for new credit card record. Note that the credit card name must be # unique within the Safe Box. # PowerShell New-CreditCard function creates a PowerShell object, which will be later used to create # an credit card record into the SecureAnyBox. # Into the new PowerShell object, specify other credit card's values. $cCardName = "new_credit_card" ## enter name of new credit card $ccard = New-CreditCard -Name $cCardName $ccard.Description = "description" $ccard.Tags.Add('tag1') ## each tag must be added individually $ccard.Tags.Add('PS_import') $ccard.Note = "noteline1`nnoteline2" ## use `n to add new line $ccard.Attributes.number = "8745 5896 1752 5963 4812" $ccard.Attributes.expiration = "2024-10-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 add any record, we need to know an id of the Safe Box to where a credit card will create. # PowerShell Add-Record function returns the credit card object. If the id from returned credit # card object is greater than zero, then the credit card creation was successful. $newRec = $ccard | Add-Record -Id $safeBoxId $credId = $newRec.id if ( $credId -gt 0 ) { Write-Host "Credit card '$cCardName' created. (id $credId )" Write-Host } } 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" } }