Advertisement
MIDItheKID

OIB-AutoTimezone Remediate

Mar 24th, 2025
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. <#
  2. .SYNOPSIS
  3. Enables the location setting and turns on the "Set the timezone automatically" switch in Time & Language > Date & Time.
  4.  
  5. .NOTES
  6. Original Author: James Robinson | SkipToTheEndpoint | https://skiptotheendpoint.co.uk
  7. Modifications by: MIDItheKID
  8. Version: v2.1
  9. Modified Date: 2025-03-24
  10.  
  11. Intune Info:
  12. Script type - Platform Script
  13. Assign to - Devices
  14. Script Settings:
  15. Run this script using the logged on credentials - No
  16. Enforce script signature check - No
  17. Run script in 64-bit PowerShell Host - Yes
  18. #>
  19.  
  20. #### Logging Variables ####
  21. $Script:ScriptName = "OIB-AutoTimezone"
  22. $Script:LogFile = "$ScriptName.log"
  23. $Script:LogsFolder = "$env:ProgramData\Microsoft\IntuneManagementExtension\Logs"
  24.  
  25. #### Script Variables ####
  26. $ErrorActionPreference = [System.Management.Automation.ActionPreference]::SilentlyContinue
  27. $Host.UI.RawUI.WindowTitle = '$ScriptName'
  28.  
  29. $LocationValue = "Allow"
  30. $AutoTZValue = "3"
  31. $LFSVCValue = "1"
  32. $SensorValue = "1"
  33.  
  34. #### Functions ####
  35. function Start-Logging {
  36. Start-Transcript -Path "$LogsFolder\$LogFile" -Append
  37. Write-Host "Current script timestamp: $(Get-Date -Format yyyy-MM-dd_HH-mm)"
  38. }
  39.  
  40. function Set-RegistryValue {
  41. param (
  42. [string]$Path,
  43. [string]$Name,
  44. [string]$Value
  45. )
  46.  
  47. # Determine property type: if the value can be cast to an integer, use DWord; otherwise, use String.
  48. $propertyType = "String"
  49. if ([int]::TryParse($Value, [ref]$null)) {
  50. $propertyType = "DWord"
  51. $Value = [int]$Value
  52. }
  53.  
  54. # Create the registry key if it does not exist.
  55. if (-not (Test-Path -Path $Path)) {
  56. Write-Host "Registry key $Path does not exist. Creating..."
  57. New-Item -Path $Path -Force | Out-Null
  58. }
  59.  
  60. try {
  61. $currentValue = (Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue).$Name
  62. if ($null -eq $currentValue) {
  63. Write-Host "Registry property $Name does not exist at $Path. Creating with value $Value..."
  64. New-ItemProperty -Path $Path -Name $Name -Value $Value -PropertyType $propertyType -Force | Out-Null
  65. }
  66. elseif ($currentValue -ne $Value) {
  67. Write-Host "Setting $Name to $Value at $Path"
  68. Set-ItemProperty -Path $Path -Name $Name -Value $Value
  69. }
  70. else {
  71. Write-Host "$Name is already set to $Value at $Path"
  72. }
  73. }
  74. catch {
  75. Write-Error "$($_.Exception.Message)"
  76. }
  77. }
  78.  
  79. #### Script ####
  80. Start-Logging
  81.  
  82. try {
  83. # Set the location value
  84. Set-RegistryValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location" -Name "Value" -Value $LocationValue
  85.  
  86. # Enable Auto Timezone value and (re)start service
  87. Set-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\tzautoupdate" -Name "Start" -Value $AutoTZValue
  88. Set-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration" -Name "Status" -Value $LFSVCValue
  89. Write-Host "(Re)Starting geolocation service"
  90. $lfsvc = Get-Service -Name lfsvc
  91. if ($lfsvc.Status -ne "Running") {
  92. Start-Service -Name lfsvc
  93. }
  94. else {
  95. Restart-Service -Name lfsvc -Force
  96. }
  97.  
  98. # Set sensor value
  99. Set-RegistryValue -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Sensor\Overrides\{BFA794E4-F964-4FDB-90F6-51056BFE4B44}" -Name "SensorPermissionState" -Value $SensorValue
  100. Exit 0
  101. }
  102. catch {
  103. Write-Error "$($_.Exception.Message)"
  104. Exit 1
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement