# The example shows how to add a file 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 file 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)" # Powershell function Set-AccessCode prompts the user to enter the Access Code # and store it on the SecureAnyBox server for a specified amount of seconds. A stored Access Code # allows saving secure fields to a new record and uploading a file. Set-AccessCode -Timeout 60 ## == value of timeout in seconds # Set the name and login for new file record. Note that the file name must be # unique within the Safe Box. # PowerShell New-File function creates a PowerShell object, which will be later used to create # an file record into the SecureAnyBox. # Into the new PowerShell object, specify other file's values and enter the full path of the file to upload. $fileName = "file_name" ## enter name of new file $file = New-File -Name $fileName $file.Description = "description" $file.Tags.Add('tag1') ## each tag must be added individually $file.Tags.Add('PS_import') $file.Note = "noteline1`nnoteline2" ## use `n to add new line $file.FileName = "name of file to upload" $file.Attributes."sec-note" = "sec-note12`nsec-note22" ## use `n to add new line ## enter full path of file to store in SecureAnyBox $filePath = "full file path" # To add any record, we need to know an id of the Safe Box to where a file will create. # PowerShell Add-Record function returns the file object. If the id from returned file # object is greater than zero, then the file creation was successful. After the validation, # file to store in the new record will upload. $newRec = $file | Add-Record -Id $safeBoxId $fileId = $newRec.id if ( $fileId -gt 0 ) { Write-Host "File '$fileName' created. (id $fileId )" Write-Host set-file -Id $fileId $filePath Write-Host "File '$filePath' uploaded to file record '$fileName'." } } 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" } }