E=mc2
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]
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/
###SETUP END###/code]
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER