# The example shows how to add a certificate 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 } # After the user logs in, it is necessary to get the id of destination Safe Box, # to where the account 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 try{ $safeBoxName = 'safebox_name' $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)" # Powershell function Set-AccessCode prompts the user to enter the Access Code # and store it on the SecureAnyBox server for specified amount of seconds. A stored Access Code # allows saving secure fields to a new record. Set-AccessCode -Timeout 60 ## == value of timeout in seconds # Set the name and login for new certificate record. Note that the certificate name must be # unique within the Safe Box. # PowerShell New-Certificate function creates a PowerShell object, which will be later used to create # an certificate record into the SecureAnyBox. # Into the new PowerShell object, specify other certificate's values and enter the full path of the certificate to upload. $certName = "cert_name" ## enter name of new certificate $cert = New-Certificate -Name $certName $cert.Description = "description" $cert.Tags.Add('tag1') ## each tag must be added individually $cert.Tags.Add('PS_import') $cert.Note = "noteline1`nnoteline2" $cert.Attributes.alias = "certificate alias" $cert.Attributes.'sec-note' = "sec-note12`nsec-note22" $cert.Attributes.filePassword = "WecO970ZAVKU7r" $certPath = "full path to certificate file" ## enter full path of certificate to store in SecureAnyBox # To add any record, we need to know an id of the Safe Box to where a certificate will create. # PowerShell Add-Record function returns the certificate object. If the id from returned # certificate object is greater than zero, then the certificate creation was successful. # After the validation, certicate to store in the new record will upload. $newRec = $cert | Add-Record -Id $safeBoxId $certId = $newRec.id if ( $certId -gt 0 ) { Write-Host "Certificate '$certName' created.(id $certId )" Write-Host set-file -Id $certId $certPath Write-Host "File '$certPath' uploaded to certificate record '$certName'." } } finally{ # When the connection is not needed anymore, disconnect from the SecureAnyBox server. # The client can no longer be used to work with the SecureAnyBox server. $loginStatus = Disconnect-SAB if(! $loginStatus.Authenticated){ Write-Host "Disconnected from SecureAnyBox server" } }