From c21c631c8fc6a3b3e9fa260f30802437f3a5189b Mon Sep 17 00:00:00 2001 From: Jens Du Four Date: Fri, 12 Jul 2024 09:55:05 +0200 Subject: [PATCH] Rework TZ detection and remeditation --- Intune_Remediation_Timezone/detection.ps1 | 18 ++++++--- Intune_Remediation_Timezone/remediation.ps1 | 42 ++++++++++++--------- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/Intune_Remediation_Timezone/detection.ps1 b/Intune_Remediation_Timezone/detection.ps1 index 0f9a2b0..513aee9 100644 --- a/Intune_Remediation_Timezone/detection.ps1 +++ b/Intune_Remediation_Timezone/detection.ps1 @@ -1,8 +1,14 @@ -if (Test-Path -LiteralPath "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location") { - $value = Get-ItemPropertyValue -LiteralPath 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location' -Name 'Value' -ErrorAction SilentlyContinue - if ($value -eq 'Allow') { - exit 0 +try{ + if (Test-Path -LiteralPath "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location") { + $value = Get-ItemPropertyValue -LiteralPath 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location' -Name 'Value' -ErrorAction SilentlyContinue + if ($value -eq 'Allow') { + write-host "Success" + exit 0 + } } } - -exit 1 \ No newline at end of file +catch{ + $errMsg = $_.Exception.Message + write-host $errMsg + exit 1 +} \ No newline at end of file diff --git a/Intune_Remediation_Timezone/remediation.ps1 b/Intune_Remediation_Timezone/remediation.ps1 index 280d3d1..3e03a24 100644 --- a/Intune_Remediation_Timezone/remediation.ps1 +++ b/Intune_Remediation_Timezone/remediation.ps1 @@ -1,19 +1,27 @@ -$RegistryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location" -$RegistryProperty = "Value" -$RegistryValue = "Allow" +try{ + $RegistryPath1 = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location" + $RegistryProperty1 = "Value" + $RegistryValue1 = "Allow" -if (!(Test-Path -LiteralPath $RegistryPath)) { - New-Item -Path $RegistryPath -Force -ErrorAction SilentlyContinue + if (!(Test-Path -LiteralPath $RegistryPath1)) { + New-Item -Path $RegistryPath1 -Force -ErrorAction SilentlyContinue + } + + New-ItemProperty -Path $RegistryPath1 -Name $RegistryProperty1 -Value $RegistryValue1 -PropertyType String -Force -ErrorAction SilentlyContinue + + $ServicePath2 = "HKLM:\SYSTEM\CurrentControlSet\Services\tzautoupdate" + $ServiceProperty2 = "Start" + $ServiceValue2 = 3 + + if (!(Test-Path -LiteralPath $ServicePath2)) { + New-Item -Path $ServicePath2 -Force -ErrorAction SilentlyContinue + } + + New-ItemProperty -Path $ServicePath2 -Name $ServiceProperty2 -Value $ServiceValue2 -PropertyType DWord -Force -ErrorAction SilentlyContinue + exit 0 } - -New-ItemProperty -Path $RegistryPath -Name $RegistryProperty -Value $RegistryValue -PropertyType String -Force -ErrorAction SilentlyContinue - -$ServicePath = "HKLM:\SYSTEM\CurrentControlSet\Services\tzautoupdate" -$ServiceProperty = "Start" -$ServiceValue = 3 - -if (!(Test-Path -LiteralPath $ServicePath)) { - New-Item -Path $ServicePath -Force -ErrorAction SilentlyContinue -} - -New-ItemProperty -Path $ServicePath -Name $ServiceProperty -Value $ServiceValue -PropertyType DWord -Force -ErrorAction SilentlyContinue +catch{ + $errMsg = $_.Exception.Message + Write-host $errMsg + exit 1 +} \ No newline at end of file