# The example shows how to view imported records to SecureAnyBox. # 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 '*'. $pattern = "*Imported*" ## use asterisks at the beginning and the end # Print the header of the results output Write-Host "[\SafeBoxGroup]\SafeBox : Id | Name | Note" Write-Host "----------------------------------------------------------------------------"`n $found = 0 # 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 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 found records are printed with parent boxes, record id, record name and Note field $path = "/" + $groupItem.Name + "/" + $boxItem.Name Write-Host $path ":" $recItem.Id "|" $recItem.Name "|" $recItem.Note $found++ } if ( $records.Count -gt 0) { Write-Host "----------------------------------------------------------------------------"`n } } } # Now the script scans the Safe Boxes in 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 ) { # 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 found records are printed with parent box, record id, record name and Note field $path = "/" + $boxItem.Name Write-Host $path ":" $recItem.Id "|" $recItem.Name "|" $recItem.Note $found++ } if ( $records.Count -gt 0) { Write-Host "----------------------------------------------------------------------------"`n } } Write-Host "Found" $found "record(s)"