Time Format issues

avatar
(anonymous user)
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.

All Comments (3)

avatar

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.

avatar

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

avatar

I realize how old this is, but I wanted to say thanks. I even tried the -AsUTC switch but that’s different, I guess.
I love and hate this program, but the biggest problem is probably my like of understanding on some core things even years into pshell.
At the very least, I wish the Ironmen would hire maybe one other person whose sole reason for employment and fleshing out the documentation and many more examples of different usage. I don’t do videos. I have to read but I’m babbling.

Anyway, THANK YOU.