# The example shows how to get list of import dates # from imported records to SecureAnyBox. # SecureAnyBox Importer utility enables to save Import stamp # "Imported yyyy MM dd hh:mm:ss" in the Note field of the record. # 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 dialogue. # Due to security reasons, we strongly recommend not using an admin user account. # Create (or use) a user account with minimum permissions (READ) only for Safe Boxes # into which records were imported 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 } # Each imported record in the Note field contains the word "Imported". # The script uses the "like" operator to filter the records found # using wildcards similar to name filtering in Windows/DOS command lines. # Therefore, the search pattern must be delimited by asterisks '*'. # A new search pattern (with asterisks at the beginning and the end) is stored # in the $workPattern variable. $pattern = "*Imported*" # use asterisks at the beginning and the end of a search pattern # Create empty list for import tags $items = @() # PowerShell commands Get-Safeboxes (imported from SABPowerShellModule.msi) # and Where-Object (standard command) are used to retrieve 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 ) { # From each of Safe Box Group, PowerShell Get-Safeboxes command retrieves nested Safe Boxes $boxes = $groupItem | Get-SafeBoxes foreach ( $boxItem in $boxes ) { # From each of Safe Box, PowerShell Get-Records and Get-Record commands retrieves nested records # The record Note field is scanned using the Where-Object command to see if it contains an import stamp. $records = $boxItem | Get-Records | Get-Record | Where-Object -Property Note -Like $pattern foreach ( $recItem in $records ) { # The record Note is scanned to get the row where the import stamp is. # The found row is added to the $items list $i = 0 while($true) { $str = ($recitem.note -split '\n')[$i] if ( $str -like $pattern ) { $items += $str break } $i++ } } } } # Now the script retrieves all Safe Boxes from the root level. # PowerShell commands Get-Safeboxes (imported from SABPowerShellModule.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 ) { # From each of Safe Box, PowerShell Get-Records and Get-Record commands retrieves nested records # The record Note field is scanned using the Where-Object command to see if it contains an import stamp. $records = $boxItem | Get-Records | Get-Record | Where-Object -Property Note -Like $pattern foreach ( $recItem in $records ) { # The record Note is scanned to get the row where the import stamp is. # The found row is added to the $items list $i = 0 while($true) { $str = ($recitem.note -split '\n')[$i] if ( $str -like $pattern ) { $items += $str break } $i++ } } } # Print the header of the results output Write-Host `n'Import dates' Write-Host $('-' * 80) # List $items is sorted and stores only unique tags $items = $items | Sort-Object $items = $items | Select -Unique # Print the list $items Write-Host `n'Found' $items.Count 'dates of import.'