Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .SYNOPSIS
- Detection script for OIB-AutoTimezone remediation.
- .DESCRIPTION
- Verifies the following settings:
- - Location: Registry HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location\Value should be "Allow".
- - Auto Timezone: Registry HKLM:\SYSTEM\CurrentControlSet\Services\tzautoupdate\Start should be "3".
- - lfsvc configuration: Registry HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration\Status should be "1".
- - Geolocation service: The lfsvc service must be present and in the Running state.
- - Sensor: Registry HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Sensor\Overrides\{BFA794E4-F964-4FDB-90F6-51056BFE4B44}\SensorPermissionState should be "1".
- #>
- try {
- $errorMessages = @()
- # Check location setting
- $locationRegPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location"
- $expectedLocation = "Allow"
- if (-not (Test-Path -Path $locationRegPath)) {
- $errorMessages += "Registry key '$locationRegPath' does not exist. Expected property 'Value' with value '$expectedLocation'."
- }
- else {
- $actualLocation = (Get-ItemProperty -Path $locationRegPath -Name "Value" -ErrorAction SilentlyContinue).Value
- if ($null -eq $actualLocation) {
- $errorMessages += "Registry property 'Value' does not exist in '$locationRegPath'. Expected '$expectedLocation'."
- }
- elseif ($actualLocation -ne $expectedLocation) {
- $errorMessages += "Location setting is incorrect. Expected '$expectedLocation', got '$actualLocation'."
- }
- else {
- Write-Host "Location setting is correctly set to '$expectedLocation'."
- }
- }
- # Check Auto Timezone registry setting
- $tzRegPath = "HKLM:\SYSTEM\CurrentControlSet\Services\tzautoupdate"
- $expectedAutoTZ = "3"
- if (-not (Test-Path -Path $tzRegPath)) {
- $errorMessages += "Registry key '$tzRegPath' does not exist. Expected property 'Start' with value '$expectedAutoTZ'."
- }
- else {
- $actualAutoTZ = (Get-ItemProperty -Path $tzRegPath -Name "Start" -ErrorAction SilentlyContinue).Start
- if ($null -eq $actualAutoTZ) {
- $errorMessages += "Registry property 'Start' does not exist in '$tzRegPath'. Expected '$expectedAutoTZ'."
- }
- elseif ($actualAutoTZ -ne $expectedAutoTZ) {
- $errorMessages += "Auto Timezone setting is incorrect. Expected '$expectedAutoTZ', got '$actualAutoTZ'."
- }
- else {
- Write-Host "Auto Timezone setting is correctly set to '$expectedAutoTZ'."
- }
- }
- # Check lfsvc service configuration registry setting
- $lfsvcRegPath = "HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration"
- $expectedLFSVC = "1"
- if (-not (Test-Path -Path $lfsvcRegPath)) {
- $errorMessages += "Registry key '$lfsvcRegPath' does not exist. Expected property 'Status' with value '$expectedLFSVC'."
- }
- else {
- $actualLFSVC = (Get-ItemProperty -Path $lfsvcRegPath -Name "Status" -ErrorAction SilentlyContinue).Status
- if ($null -eq $actualLFSVC) {
- $errorMessages += "Registry property 'Status' does not exist in '$lfsvcRegPath'. Expected '$expectedLFSVC'."
- }
- elseif ($actualLFSVC -ne $expectedLFSVC) {
- $errorMessages += "lfsvc configuration is incorrect. Expected '$expectedLFSVC', got '$actualLFSVC'."
- }
- else {
- Write-Host "lfsvc configuration is correctly set to '$expectedLFSVC'."
- }
- }
- # Check geolocation service (lfsvc) status
- $lfsvcService = Get-Service -Name lfsvc -ErrorAction SilentlyContinue
- if ($null -eq $lfsvcService) {
- $errorMessages += "lfsvc service is not found."
- }
- elseif ($lfsvcService.Status -ne "Running") {
- $errorMessages += "lfsvc service is not running. Current status: $($lfsvcService.Status)."
- }
- else {
- Write-Host "lfsvc service is running."
- }
- # Check sensor registry value
- $sensorRegPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Sensor\Overrides\{BFA794E4-F964-4FDB-90F6-51056BFE4B44}"
- $expectedSensor = "1"
- if (-not (Test-Path -Path $sensorRegPath)) {
- $errorMessages += "Registry key '$sensorRegPath' does not exist. Expected property 'SensorPermissionState' with value '$expectedSensor'."
- }
- else {
- $actualSensor = (Get-ItemProperty -Path $sensorRegPath -Name "SensorPermissionState" -ErrorAction SilentlyContinue).SensorPermissionState
- if ($null -eq $actualSensor) {
- $errorMessages += "Registry property 'SensorPermissionState' does not exist in '$sensorRegPath'. Expected '$expectedSensor'."
- }
- elseif ($actualSensor -ne $expectedSensor) {
- $errorMessages += "Sensor value is incorrect. Expected '$expectedSensor', got '$actualSensor'."
- }
- else {
- Write-Host "Sensor value is correctly set to '$expectedSensor'."
- }
- }
- # Evaluate detection result
- if ($errorMessages.Count -gt 0) {
- foreach ($msg in $errorMessages) {
- Write-Host $msg
- }
- Exit 1
- }
- else {
- Write-Host "All settings are correctly configured."
- Exit 0
- }
- }
- catch {
- Write-Error "Detection encountered an error: $($_.Exception.Message)"
- Exit 1
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement