Avatar of E=mc2
E=mc2
Flag for Canada asked on

How to modify Powershell script to use 0 as current day

I would like to modify this Powershell script so if you enter the number 0, it will accept today's date.
If Enter is pressed, it should not move ahead until only a Number is entered for the amount of days back.

Thanks in advance.

[code]$userDays = Read-Host -Prompt "How many days ago is this report for (no input = today)"
If ($userDays -ne $null) {
      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###/code]
PowershellScripting Languages

Avatar of undefined
Last Comment
E=mc2

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
oBdA

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
E=mc2

ASKER
Perfect, thank you.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy