# The example shows how to delete records containing a specified text # pattern in the record Note field. # SecureAnyBox Importer utility enables to save Import stamp # "Imported yyyy MM dd hh:mm:ss" in the Note field of the record. # This example shows how to delete all records imported using # the SecureAnyBox Importer utility in the 2021 (records contain # the text"Imported 2021" in the record note). # If you want to use PowerShell commands to work with SecureAnyBox, first # install SecureAnyBoxPowerShellModule.msi # First we need to authenticate the user. Connect-Sab command connects to SecureAnyBox and # opens the login dialog. # Due to security reasons we strongly recommend not using an admin user account. # Create (or use) a user account with minimum permissions (READ and DELETE) only # for the Safe Box, from which the records will delete, 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 dialog for entering the code if ( $loginStatus.SecondFactorRequired ) { set-2fa } # The script uses the "like" operator to filter the found records using # wildcards similar to how it is used to filter names # in Windows/DOS command lines # Therefore, the search pattern must be delimited by asterisks '*'. $pattern = "*Imported 2021*" # use asterisks at the beginning and the end of a search pattern $deleted = 0 # Print the header of the results output Write-Host "[\SafeBoxGroup]\SafeBox : Id | Name | Note" Write-Host "----------------------------------------------------------------------------"`n # We now scan the Safe Box Groups and their nested Safe Boxes. # PowerShell Get-Safeboxes command (imported from SecureAnyBoxPowerShellModule.msi) # and Where-Object (standard command) are used to get an # array of Safe Box objects according to a specified condition (get Safe Box Groups only). $groups = Get-SafeBoxes | Where-Object { $_.Type -eq "SAFEBOX_GROUP" } foreach ( $groupItem in $groups ) { # Retrieve nested Safe Boxes from each Safe Box Group using Powershell command Get-SafeBoxes $boxes = $groupItem | Get-SafeBoxes foreach ( $boxItem in $boxes ) { # PowerShell commands Get-Records, Get-Record and Where-Object are used to retrieve # an array of records according to a specified condition (Note is like a specified pattern). # The Get-Records cmdlet returns all records from the Safe Box ($boxItem) but does not # return value from the Note field. # The Get-Record command returns all unencrypted record values (if the access code is # not stored on the SecureAnyBox server). $records = $boxItem | Get-Records | Get-Record | Where-Object -Property Note -Like $pattern foreach ( $recItem in $records ) { $path = "\" + $groupItem.Name + "\" + $boxItem.Name Write-Host -NoNewline $path ":" $recItem.Id "|" $recItem.Name "|" $recItem.Note # PowerShell Remove-Record command (imported from SecureAnyBoxPowerShellModule.msi) # deletes the record from the Safe Box (deleted records can be restored on the # Deleted page on the SecureanyBox server). Remove-Record -Id $recItem.Id Write-Host(' DELETED') $deleted++ } if ( $records.Count -gt 0) { Write-Host "----------------------------------------------------------------------------"`n } } } # Now the script gets Safe Boxes from the root level. # PowerShell commands Get-Safeboxes (imported from SecureAnyBoxPowerShellModule.msi) # and Where-Object (standard command) are used to retrieve an array of Safe Box # objects according to a specified condition (get Safe Boxes only) $boxes = Get-SafeBoxes | Where-Object { $_.Type -eq "SAFEBOX" } foreach ( $boxItem in $boxes ) { # PowerShell commands Get-Records, Get-Record and Where-Object are used to retrieve # an array of records according to a specified condition (Note is like a specified pattern). # The Get-Records cmdlet returns all records from the Safe Box ($boxItem) but does not # return value from the Note field. # The Get-Record command returns all unencrypted record values (if the access code is # not stored on the SecureAnyBox server). $records = $boxItem | Get-Records | Get-Record | Where-Object -Property Note -Like $pattern foreach ( $recItem in $records ) { $path = "\" + $boxItem.Name Write-Host -NoNewline $path ":" $recItem.Id "|" $recItem.Name "|" $recItem.Note # PowerShell Remove-Record command (imported from SecureAnyBoxPowerShellModule.msi) # deletes the record from the Safe Box (deleted records can be restored on the # Deleted page on the SecureanyBox server). Remove-Record -Id $recItem.Id Write-Host "Record '" $recItem.Name "' deleted.`n" $deleted++ } if ( $records.Count -gt 0) { Write-Host "----------------------------------------------------------------------------"`n } } Write-Host "`n $deleted record(s) deleted `n`n----------------------------------------------------------------------------"`n