RamblingCookieMonster / SecretServer

Secret Server PowerShell Module
MIT License
87 stars 28 forks source link

generate password if password is empty #16

Open Plork opened 8 years ago

Plork commented 8 years ago

see https://thycotic.force.com/support/s/article/PowerShell-Add-Update-Secret-Example for example.

Jaykul commented 8 years ago

I can't test this at the moment.

Plork commented 8 years ago

Only problem with this I had was the $script scoped Templates variable I mailed you about. I removed it locally and then this works.

Op ma 26 sep. 2016 om 07:06 schreef Joel Bennett notifications@github.com:

I can't test this at the moment.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/RamblingCookieMonster/SecretServer/pull/16#issuecomment-249480120, or mute the thread https://github.com/notifications/unsubscribe-auth/AEBGLxgNpYxvMz8p8XagGp_vVFwQ3FUoks5qt1LHgaJpZM4J8Hr8 .

Plork commented 8 years ago

the Templates variable is a script scoped variable. I guess this is so you don’t have to get the templates everytime. This has a weird side effect tho I can’t explain.

A noteproperty gets added with to $Field with the values of the input parameters. Somehow these extra properties get added to the $script:secretTemplates as well. So the template in the script scope gets the values that are added to $field.

I would have thought that because you create a new variable $fields = $Template.Fields it would “copy” the $template variable into a new one and the the original does not gets altered.

I say this because I edited the script to allow to leave the password field empty. That way thycotic wil generate a password based on the requirements specified in the template. (So I don’t have to generate a password myself.) But because the script scoped $secretTemplates got the values of the $Fields variable the 2nd time I run the script the values of the first loop are still in there. My “if password is empty” fails because of this. (it’s only empty the first iteration).