I have a function that is using if statements for the parameter passed
it works fine if the parameter and value are given
but if the parameter is not passed and just the value given it will just error
even though I have a default set.
Is there a way to make an if statement on the value itself?
like if the parameter value -match “@” it equals the parameter $email else it equals the parameter $SAN
Hudzon,
Welcome back to the forum. Long time no see.
Please share your code and error messages you might get.
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Here is my little fuction, what I would like is for the user to be able to pass either or prameter without having to declare it and the scipt determine which one it is based on the email address having the @ symbol in the string.
To set a default value for a parameter you assign it as you would any other variable with “= ‘VALUE’” within the Param-block.
If a user passes in a different value it overwrites the value you assigned previously.
Also if you set a default parameter you will have to either skip the Mandatory part of the parameter assignment as the user can choose to not assign a value when calling the script.
I think the easiest way to achieve your goal is to limit to a generic parameter and just check the value yourself. You could even extend this to accept samaccountname, distinguishedname, etc. In order to improve readability I stored your calculated expressions/properties in a variable. I also encourage you to look into splatting as well.
My final bit of advice is to limit the properties you query with Get-ADUser to those you actually use. The increased load on active directory In small environments this isn’t really an issue, but can be very disruptive in larger organizations.