OSDeploy / OSD

OSD Shared Functions
MIT License
149 stars 61 forks source link

Issue with Set-TimeZoneFromIP #110

Closed JHBDO closed 6 months ago

JHBDO commented 7 months ago

Describe the bug It appears that the $TimeZone variable in the Set-TimeZoneFromIP function is an array that contains two items. The command Set-TimeZone -Name $TimeZone throws an error.

To Reproduce Steps to reproduce the behavior:

  1. In OOBE, call the Set-TimeZoneFromIP function.
  2. See error in Additional context below

Expected behavior Function should set the timezone without an error.

Desktop (please complete the following information):

Additional context When I call Set-TimeZoneFromIP from my script in the OOBE phase, it returns the error: Set-TimeZone : Cannot convert 'System.Object[]' to the type 'System.String' required by the parameter 'Name'. Specified method is not supported.

I'm in the Eastern timezone, and when I debug the function, I see that the $TimeZone variable is an array containing: Eastern Standard Time Eastern Daylight Time

Based on the error message, I'm assuming this should be returning only 1 item as a string, and not an array. $TimeZone.GetType() says the variable is an object with BaseType System.Array.

gwblok commented 7 months ago

Thanks, I just had to re-write the function recently, as the API I was using before started charging. I haven't done much testing yet. I'll take a look.

JHBDO commented 7 months ago

Thanks Gary. As a temporary workaround, I added this code to Set-TimeZoneFromIP. It compares the time zone offset value in order to narrow it down to one. It was generated by Microsoft Copilot, so there's probably a more efficient way to do it. :-)

##Additionally matches on time zone offset value to fix an issue with mutiple Daylight/Standard values being returned
    $offset = ($TimeZoneAPIInfo.utc_offset).Substring(0,3)
        if ($offset.Substring(1,1) -eq "0") {
            $offset = $offset.Substring(0,1) + $offset.Substring(2,1)
        }
    return ($TimeZoneData | Where-Object {$_.utc -match $TimeZoneAPIInfo.timezone -and $_.offset -match $offset}).value
gwblok commented 7 months ago

Thanks, can you try the updated code here: https://github.com/OSDeploy/OSD/blob/master/Public/OSDCloudTS/Get-TimeZoneFromIP.ps1

The problem was, while your updated code worked in your timezone, it didn't work in my timezone, it returned zero results.
So I used your code and added another if statement. Hopefully that works for most people.

I'm tempted to just have it so you can set a variable with the time zone, and it will apply that time zone for you, instead of trying to do a lookup based on the IP address. (when doing zero touch deployments)

Basically make a table based on this data: https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/default-time-zones?view=windows-11.

$Global:MyOSDCloud.TimZone = "Eastern Standard Time"

Thoughts on that?

JHBDO commented 7 months ago

For me personally, having the time zone set based on IP geo is a must, as we have locations across the globe. Using the IP really cuts down on the number of configs I need for ZTI.


From: gwblok @.> Sent: Thursday, February 15, 2024 5:43 PM To: OSDeploy/OSD @.> Cc: Joe Hegyi @.>; Author @.> Subject: Re: [OSDeploy/OSD] Issue with Set-TimeZoneFromIP (Issue #110)

Attention: This e-mail was sent from someone outside of BDO Global Office. Always use caution when opening attachments or clicking links from unknown senders or when receiving unexpected e-mails.

Thanks, can you try the updated code here: https://github.com/OSDeploy/OSD/blob/master/Public/OSDCloudTS/Get-TimeZoneFromIP.ps1

The problem was, while your updated code worked in your timezone, it didn't work in my timezone, it returned zero results. So I used your code and added another if statement. Hopefully that works for most people.

I'm tempted to just have it so you can set a variable with the time zone, and it will apply that time zone for you, instead of trying to do a lookup based on the IP address. (when doing zero touch deployments)

Basically make a table based on this data: https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/default-time-zones?view=windows-11.

$Global:MyOSDCloud.TimZone = "Eastern Standard Time"

Thoughts on that?

— Reply to this email directly, view it on GitHubhttps://github.com/OSDeploy/OSD/issues/110#issuecomment-1947458491, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKS2LN6DOPU7OTHUDEVSLFTYT2FSZAVCNFSM6AAAAABDHCE7OOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBXGQ2TQNBZGE. You are receiving this because you authored the thread.Message ID: @.***>

Global IT & Services B.V. (“Global IT”) is a limited liability company registered in the Netherlands with KVK number 17239055 and VAT number NL8203.71.476.B01. It is a subsidiary of the Belgian company Brussels Worldwide Services BV (‘BWS’), that coordinates service provision within the international BDO network of independent member firms ('the BDO network'). Global IT provides services to BWS and the BDO network. Global IT, BWS and the BDO Member Firms are separate legal entities and have no liability for each other's acts or omissions. Nothing in the arrangements or rules of the BDO network shall constitute or imply an agency relationship between Global IT and the member firms of the BDO network. BDO is the brand name for the BDO network and for each of the BDO member firms.

gwblok commented 7 months ago

@JHBDO with the updated changes, has this been working for you now? I don't have a way to test most Time Zones, so hopefully as other have issues, we can just fix those bugs as they come

gwblok commented 6 months ago

Considering Closed until someone else has an issue in their TimeZone.