Navarro_refugee
Navarro_refugee

Reputation: 31

Set timezone within PowerShell Get-Date?

Is there a way to adjust the timezone within a Get-Date statement? I'm trying to run the following command within a PowerShell module and the date and time for the results it generates are all in PST, I'm trying to get everything into EST.

Start-Five9Report -FolderName [name] -ReportName [name] -EndDateTime (Get-Date).AddMinutes(-1) -StartDateTime (Get-Date).AddMinutes(-10)

Upvotes: 3

Views: 2905

Answers (1)

codewario
codewario

Reputation: 21418

Yes, use the TimeZoneInfo.ConvertTimeBySystemTimeZoneId static method. This can be done on one line but I broke it up for readability:

[System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId(
  [DateTime]::Now,
  "Eastern Standard Time"
)

You can use ( Get-Date ) in place of [DateTime]::Now if you wish.


For the destinationTimeZoneId argument "Central Standard Time", you can get the correct Id to use for each time zone by running the TimeZoneInfo.GetSystemTimeZones static method:

[System.TimeZoneInfo]::GetSystemTimeZones()

and making note of the Id property value for the time zone you want. Note that each time zone is aware of whether it should follow Daylight Savings Time or Standard Time. You do not need to (nor will it work) provide an alternate Id for DST-enabled time zones.

Upvotes: 3

Related Questions