How do I..

How would I read this variable ($strCSVSuffix) so that an if/else command would send emails to one address on the first of the month and another the remaining days of the month?  

I feel that I probably need a Regular Expression to evaluate the date string and I just don't fully understand building Regular expressions still.

There is obviously much more to this script but this one component I need to get changed so I don't have to keep manually sending this stuff to someone else on the first of the month.   

$strCSVSuffix = (get-date).toString('yyyyMMdd')

if ($strCSVSuffix -eq "01")  {

$AdminEmailAddress = "blah blah blah"

}

else {

$AdminEmailAddress = "another blah blah blah"

}

}

  • Your question is fairly vague, but you can, In a scheduled task (which execute daily), just use what you have in a script with the Send-MailMessage cmdlet .


        # get function / cmdlet details
        (Get-Command -Name Send-MailMessage).Parameters
        Get-help -Name Send-MailMessage -Examples
        Get-help -Name Send-MailMessage -Full
        Get-help -Name Send-MailMessage -Online


        Clear-Host
        if ($FirstDayOfMonth = (Get-Date (Get-Date -Format "MM/dd/yyyy") -Day 1))
        {
            "Processing mail for the first day of the current month - $FirstDayOfMonth"
            $AdminEmailAddress = "blah blah blah"
            # Send-MailMessage ...
        }
        else
        {
            "Not the first day of the current month. Process mail on remaing days of the month $(Get-Date)"
            $AdminEmailAddress = "another blah blah blah"
            # Send-MailMessage ...
        }