Modify script to prompt user

I would like to modify this PS script so that it prompts the person that is running the script to enter how many days ago the report is for.
At the moment the script is set for 1 day ago, however I want it to prompt the user and then they user can enter 1,2,3 or 4 etc.. days back.. and then it will run the script based on whatever the user has input..

Thanks,

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

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

 ###PROGRAM START###
      # Invokes the Send-MailMessage function to send notification email
      $splat = @{
            From =                  'email1@mail.com'
            To =                  Get-Content -Path ( Join-Path $PSScriptRoot 'EmailDist.txt')
            SmtpServer =      'smtp.email.com'
            Subject =            $subject
            body =                  $MessageBody
            BodyAsHtml =      $true
            Attachment =      ( Join-Path $PSScriptRoot 'Attachment.pdf' )
      }
      Send-MailMessage @splat
###PROGRAM END###
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:
Try this:
$userDays = Read-Host -Prompt "How many days ago is this report for (no input = 1 day)"
If ($userDays) {
	Try {
		$daysAgo = [Int32]$userDays
	} Catch {
		Write-Warning "'$($userDays)' is not a number; will use 1 day!"
		$daysAgo = 1
	}
} Else {
	$daysAgo = 1
}
###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 for: "+$date+" "
	#Body of Email
		$MessageBody = "Attached is the Report for $date. Thank you."
###USER VARIABLES END###

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

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
100questionsAuthor Commented:
@ObdA.. thank you very much.  This works well.  However if I want to change it so that I have an option for the date being today, in addition to any past dates, would much have to be modified for this?
0
oBdACommented:
You mean to allow 0 days?
Easy fix: in line 2, replace
If ($userDays) {
with
If ($userDays -ne $null) {
0
100questionsAuthor Commented:
Many thanks for all your help.
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.