Modify Powershell report to show a calendar

I would like to modify this script, so that a calendar showing the last 30 days shows, after which at that time the users can input how many days back they want to the report to run.

[code]$maxDays = 365
Do {
      $userDays = Read-Host -Prompt "How many days ago is this report for (0 = today, max $($maxDays), X = exit)"
      $userDays = $userDays.Trim()
} Until (($userDays -eq 'X') -or (($userDays -match '\d+') -and ($maxDays -ge $userDays)))
If ($userDays -eq 'X') {
      Exit
}
$daysAgo = [Int32]$userDays
$daysAgo
###SETUP START###
#-------DO NOT MODIFY-------#
      #Yesterdays Date
            $date = ((Get-Date).AddDays((-1 * $daysAgo))).ToString("MMM'/'dd'/'yyyy")
###SETUP END###

###USER VARIABLES START###
#-------MODIFY AS NEEDED-------#
    #Mail Subject
        $Subject = "Report: "+$date+" "
    #Body of Email
        $MessageBody = "Attached is theReport for $date. Thank you."
###USER VARIABLES END###

###PROGRAM START###
      # Invokes the Send-MailMessage function to send notification email
      $splat = @{
            From =                  'email1@email.com'
            To =                  Get-Content -Path ( Join-Path $PSScriptRoot 'EmailDistList.txt')
            SmtpServer =      'smtp.server.com'
            Subject =            $subject
            body =                  $MessageBody
            BodyAsHtml =      $true
            Attachment =      ( Join-Path $PSScriptRoot 'Attachment.pdf' )
      }
      Send-MailMessage @splat
###PROGRAM END###/code]
100questionsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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:
This now uses the selected date directly:
Function Select-DateForm {
[CmdletBinding()]
Param(
	[String]$Title,
	[String]$Prompt,
	[DateTime]$MinDate,
	[DateTime]$MaxDate
)
	Function Show-FormMain {
		Add-Type -AssemblyName System.Drawing
		Add-Type -AssemblyName System.Windows.Forms
		[System.Windows.Forms.Application]::EnableVisualStyles()

		$formMain = New-Object -TypeName System.Windows.Forms.Form
		$formMain.ClientSize = New-Object -TypeName 'System.Drawing.Size' -ArgumentList 208, 250
		$formMain.FormBorderStyle = 'FixedSingle'
		$formMain.MaximizeBox = $false
		$formMain.MinimizeBox = $true
		$formMain.Text = If ($Title) {$Title} Else {'Date Selection'}
		
		$labelPrompt = New-Object -TypeName System.Windows.Forms.Label
		$labelPrompt.Location = New-Object -TypeName 'System.Drawing.Point' -ArgumentList 16, 8
		$labelPrompt.AutoSize = $true
		$labelPrompt.Text = If ($Prompt) {$Prompt} Else {'Please select a date:'}
		$formMain.Controls.Add($labelPrompt)

		$monthCalendar = New-Object -TypeName System.Windows.Forms.MonthCalendar
		$monthCalendar.Location = New-Object -TypeName 'System.Drawing.Point' -ArgumentList 16, 32
		$monthCalendar.MaxSelectionCount = 1
		If ($MinDate) {$monthCalendar.MinDate = $MinDate}
		If ($MaxDate) {$monthCalendar.MaxDate = $MaxDate}
		$formMain.Controls.Add($monthCalendar)
		
		$buttonOK = New-Object -TypeName System.Windows.Forms.Button
		$buttonOK.Location = New-Object -TypeName 'System.Drawing.Point' -ArgumentList 40, 208
		$buttonOK.Size = New-Object -TypeName 'System.Drawing.Size' -ArgumentList 72, 25
		$buttonOK.Text = '&OK'
		$buttonOK.add_Click({
			Param($Sender, $EventArgs)
				$Script:returnValue = $monthCalendar.SelectionStart
				$formMain.Close()
			})
		$formMain.Controls.Add($buttonOK)
		
		$buttonCancel = New-Object -TypeName System.Windows.Forms.Button
		$buttonCancel.Location = New-Object -TypeName 'System.Drawing.Point' -ArgumentList 120, 208
		$buttonCancel.Size = New-Object -TypeName 'System.Drawing.Size' -ArgumentList 72, 25
		$buttonCancel.Text = '&Cancel'
		$formMain.Controls.Add($buttonCancel)

		$formMain.CancelButton = $buttonCancel
		$formMain.AcceptButton = $buttonOK
		
		[void]$formMain.ShowDialog()
	}
	Show-FormMain
	Return $returnValue
}

$maxDays = 30
$reportDate = Select-DateForm -Prompt 'Select the report start date:' -MinDate ([DateTime]::Now.AddDays(-1 * $maxDays)) -MaxDate ([DateTime]::Now)
If (-not $reportDate) {
      Exit
}
$reportDate

###SETUP START###
#-------DO NOT MODIFY-------#
      #Yesterdays Date
            $date = $reportDate.ToString("MMM'/'dd'/'yyyy")
###SETUP END###

###USER VARIABLES START###
#-------MODIFY AS NEEDED-------#
    #Mail Subject
        $Subject = "Report: "+$date+" "
    #Body of Email
        $MessageBody = "Attached is theReport for $date. Thank you."
###USER VARIABLES END###

###PROGRAM START###
      # Invokes the Send-MailMessage function to send notification email
      $splat = @{
            From =                  'email1@email.com'
            To =                  Get-Content -Path ( Join-Path $PSScriptRoot 'EmailDistList.txt')
            SmtpServer =      'smtp.server.com'
            Subject =            $subject
            body =                  $MessageBody
            BodyAsHtml =      $true
            Attachment =      ( Join-Path $PSScriptRoot 'Attachment.pdf' )
      }
      Send-MailMessage @splat
###PROGRAM END###

Open in new window

2

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
100questionsAuthor Commented:
Thanks so much.  This seems to work however I can't seem to see the Saturday dates since the Windows is cut off on the right side.. I am not fully able to see the calendar window.... Is there a way so that I can also see the Saturday dates on the right side?
Thanks so much in advance, however this would be perfect if I was just able to see those dates.
0
oBdACommented:
Did you get it fixed by increasing the form width, or do you still need help with this?
1
100questionsAuthor Commented:
Yes thanks so much I got this working
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.