Time Format issues

Product: PowerShell Universal
Version: 3.9.1

I am trying to schedule a script to run from another script, 30 minutes in the future, but having problems getting it to do so.

Here is the code:

$Date = (get-date).AddMinutes(30).ToString(“MM/dd/yyyy HH:mm:ss”)

New-PSUSchedule -Script “Email.ps1” -OneTime $Date -Name “User Email” -TimeZone America/Phoenix

I have tried with and without the timezone, various date formats, and I can get it 7 hours prior or more, but never to be 30 minutes in the future. I assume it is the date string, and I could probably add the 7 hours, (Arizona is -7) but that seems a bit janky.

It is part of a larger user creation process and the automated email goes out about 30 minutes after the account is created to allow time for O365 to actually create the account and mailbox.

I modified the to this:

$date = (get-date).addminutes(30).ToUniversalTime()

Seems to schedule properly now, but not sure why it is defaulting to UTC time and not local system time in the first place.

1 Like

Thank you for this! I did not see this documented anywhere!