# The example shows how to add an account 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 account will create. $safeBoxName = 'safeboxName' # 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 $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)" # Set the name and login for new account record. Note that the account name must be # unique within the Safe Box. # PowerShell New-Account function creates an object, which will be later used to create # an account record into the SecureAnyBox. # Into the new PowerShell object, specify other account's values. $accountName = "new_account" ## enter name of new account $loginName = "loginname" ## enter login name of new account $acc = New-Account -Name $accountName -LoginName $loginName $acc.ServerAddress = "server_address" $acc.Site = "site" $acc.Description = "description" $acc.Tags.Add('tag1') ## each tag must be added individually $acc.Tags.Add('PS_import') $acc.Note = "noteline1`nnoteline2" ## use `n to add new line $acc.Launcher = "NONE" ## select one of the values : NONE, REMOTE_DESKTOP, SSH, SFTP, SCP, TELNET, FTP, RASDIAL, WINBOX $acc.Password = "hyBE719lExma6w" $acc.PasswordRe = "hyBE719lExma6w" ## repeat password # To add any record, we need to know an id of the Safe Box to where an account # will create. # PowerShell Add-Record function returns the account object. If the id from # returned account object is greater than zero, then the account creation was # successful. $newRec = $acc | Add-Record -Id $safeBoxId $accId = $newRec.id if ( $accId -gt 0 ) { Write-Host "Account '$accountName' created. (id $accId )" Write-Host } } 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" } }