Power Shell invalid syntax.

Hi Experts, I am very new to PowerShell scripting, came across an script that is for AD password expiry notification from TechNet, I tried to input the variables, but somehow there is some error that I don't really understand.

The first error is Missing ')' in function parameter list.
The second error is Unexpected token ')' in expression or statement.

Kindly refer to the attached file for the scripting error syntax, and the original file that I have download from TechNet.

The file that I have download is from this source.

https://gallery.technet.microsoft.com/scriptcenter/Password-Expiry-Email-177c3e27

Kindly advise.
scripting-issue.png
norman engIT AdminAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
These are not parameters you're supposed to edit, you're supposed to pass them in the command line when calling the script.
As in
.\PasswordChangeNotification.ps1 -smtpServer mail.abcdefg.com -expireInDays 10 -from abcdef@abcdefg.com ...

Open in new window

Or if you edit the script (which means these values will be taken as default when they're not passed in the command line, then keep the comma at the end of the line
    [Parameter(Mandatory=$True,Position=0)] 
    [ValidateNotNull()] 
    [string]$smtpServer = "mail.abcdefg.com", 
    # Notify Users if Expiry Less than X Days 
    [Parameter(Mandatory=$True,Position=1)] 
    [ValidateNotNull()] 
    [int]$expireInDays = 10,
...

Open in new window

0
norman engIT AdminAuthor Commented:
hi oBdA thank you for your input, it has indeed resolve the error, but after I have edited the script inputting the default value (Kindly refer to the attached scripting issue_v2) , and run the script, it will prompt me to input the value again, (kindly refer to the prompting.png).

kindly advise.

Thanks.
Scripting-issue_v2.PNG
Prompting.PNG
0
oBdACommented:
Forgot about that, sorry - that's what happens with mandatory parameters, they can't have default values.
In the parameters decoration before the respective argument variable, you'd need to set Mandatory=$false
    [Parameter(Mandatory=$false,Position=0)] 
    [ValidateNotNull()]
    [string]$smtpServer = "mail.abcdefg.com", 
    # Notify Users if Expiry Less than X Days 
    [Parameter(Mandatory=$false,Position=1)] 
    [ValidateNotNull()] 
    [int]$expireInDays = 10,
    ...

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
norman engIT AdminAuthor Commented:
Hi oBdA, got it, thanks alot.
0
norman engIT AdminAuthor Commented:
thanks alot, it works.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.