none
Missing Statement Block on PowerShell Script RRS feed

  • Question

  • Hello, 

    Can someone please share exactly what's wrong with this PS script?

        # Send Email Message
        if ($daystoexpire -ge "1") -and ($daystoexpire -lt $expireindays)}
    {
             # If Logging is Enabled Log Details
            if (($logging) -eq "Enabled")}
            {
                Add-Content $logfile "$date,$Name,$emailaddress,$daystoExpire,$expireson" 
            }
            # Send Email Message
            Send-Mailmessage -smtpServer $smtpServer -from $from -to $emailaddress -subject $subject -body $body -bodyasHTML -priority High  

    Error

    At line:140 char:30
    +     if ($daystoexpire -ge "1") -and ($daystoexpire -lt $expireindays)}
    +                              ~
    Missing statement block after if ( condition ).
    At line:143 char:38
    +         if (($logging) -eq "Enabled" }
    +                                      ~
    Missing closing ')' after expression in 'if' statement.
    At line:152 char:1
    + }# End User Processing
    + ~
    Unexpected token '}' in expression or statement.
        + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : MissingStatementBlock

    Thanks 


    • Moved by Bill_Stewart Friday, July 7, 2017 4:17 PM This is not "fix/debug/rewrite my script for me" forum
    Monday, May 1, 2017 3:37 AM

All replies

  • If you make an effort to format your code correctly you will be able to see the errors.

    Also never match a number to a string as it will give you unexpected results when you least expect it.


    \_(ツ)_/


    • Edited by jrv Monday, May 1, 2017 4:51 AM
    Monday, May 1, 2017 4:50 AM