Forum Discussion
KevinSmith
Oct 26, 2021Copper Contributor
PowerShell function calling itself is loopy
I'm terrible at PowerShell. But, I'm writing a PS script to add the distinguishedName of specific users more easily to the authOrig attribute in AD. If you aren't familiar, you can't just modify t...
J Mymryk
Nov 05, 2021Copper Contributor
Welcome to PowerShell it can be a bit confusing. Basically you have a function but no main Script. I suggest the following:
Put your prompt for the group out of the function and have it in a do while loop that exits if q is entered.
After the group input is entered you test for Q with an if statement and you then have an else if statement that passes the group name to your function. Functions are always defined at the beginning of the script so your Main script starts after the functions are created. https://adamtheautomator.com/powershell-functions/ provides some good information on how to create a function and pass it information.
James
Put your prompt for the group out of the function and have it in a do while loop that exits if q is entered.
After the group input is entered you test for Q with an if statement and you then have an else if statement that passes the group name to your function. Functions are always defined at the beginning of the script so your Main script starts after the functions are created. https://adamtheautomator.com/powershell-functions/ provides some good information on how to create a function and pass it information.
James