cyberark / epv-api-scripts

These API scripts enable CyberArk users to automate privileged account management task like account creation, user management, and more.
https://www.cyberark.com/best
Apache License 2.0
195 stars 175 forks source link

AOU - unable to create safes based on template safe #386

Open NathTheDude opened 8 months ago

NathTheDude commented 8 months ago

Summary

Although selecting -templatesafe parameter when running this script, no new safes are created for accounts when the safe does not exist already.

Steps to Reproduce

  1. Run the AOU script including the parameters -create and -templatesafe

Expected Results

Script reads a line for an account to be onboarded script should check if safe exists If safe exists, carry on and check if account already exists and then onboard account if unique if safe does not exist, create a new safe carry on going through csv for each account on there.

Actual Results

When attempting to onboard an account where the safe does not already exist, the logic seems to fail. If the safe does ot does not exist the output in the debug log states 'Safe exists.

Seems like the logic for the function 'Test-Safe' is bad with $true always being returned ` try { If ($null -eq $(Get-Safe -safeName $safeName -ErrAction "SilentlyContinue")) {

Safe does not exist

        Write-LogMessage -Type Warning -MSG "Safe $safeName does not exist"
        return $false
    } else {
        # Safe exists
        Write-LogMessage -Type Info -MSG "Safe $safeName exists"
        return $true
    }
} catch {
    Write-LogMessage -Type Error -MSG "Error testing safe '$safeName' existence. Error: $(Join-ExceptionMessage $_.Exception)" -ErrorAction "SilentlyContinue"
}

`

Reproducible

Version/Tag number

What version of the product are you running? Any version info that you can share is helpful. For example, you might give the version from Docker logs, the Docker tag, a specific download URL, the output of the /info route, etc.

Environment setup

Additional Information

Add any other context about the problem here.