-
Notifications
You must be signed in to change notification settings - Fork 247
Enable Windows Location Services
directorcia edited this page Dec 3, 2025
·
1 revision
This document explains the execution, parameters, operations, changes, and troubleshooting for the PowerShell script enable-location-services.ps1.
- Requires: Run PowerShell as Administrator
- OS: Windows
- Output: Console messages (optional), transcript file in C:\Temp when -Silent is used
Enable Windows Location Services system-wide and for the current user:
- Start and set Geolocation Service (lfsvc) to Automatic
- Clear any policy that disables location
- Set system flag to turn Location Services ON
- Enable user-level app capability for location
- Optional reboot and optional silent transcript logging
- -ForceReboot: Reboots the machine after changes are applied
- -Silent: Suppresses console output and writes a transcript to C:\Temp\location-enable.log
Exit codes:
- 0: Success (may include non-fatal warnings)
- 10: Service configuration failure (lfsvc)
- 20: Policy update failure (HKLM policy)
- 30: Registry configuration status failure (system toggle)
- 40: User consent failure (HKCU capability)
- Admin Rights Check
- Verifies the process is elevated using WindowsPrincipal
- If not administrator, script terminates with error guidance
- Optional Silent Transcript
- If -Silent:
- Ensures C:\Temp exists
- Starts transcript C:\Temp\location-enable.log (append mode)
- Suppresses Write-Host messages; warnings/errors still recorded
- Geolocation Service (lfsvc)
- Get-Service lfsvc
- If StartupType != Automatic:
- Set-Service -StartupType Automatic
- If Status != Running:
- Start-Service lfsvc
- On failure:
- Warn and set exit code 10 (continues processing)
- Clear Group Policy that disables location
- Path: HKLM:\SOFTWARE\Policies\Microsoft\Windows\Location
- Value: DisableLocation (DWORD)
- If present, set DisableLocation=0 (enables location)
- On failure:
- Warn and set exit code 20 (continues processing)
- Enable system Location Services flag
- Path: HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration
- Value: Status (DWORD, 1=On, 0=Off)
- Ensures key exists, sets Status=1
- On failure:
- Warn and set exit code 30 (continues processing)
- Allow user-level location capability
- Path: HKCU:\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location
- Value: Value (String, 'Allow')
- Ensures path exists, sets Value='Allow'
- On failure:
- Warn and set exit code 40 (continues processing)
- Final Output and Reboot
- If not -Silent: prints success guidance and suggests sign-out/in or reboot if the toggle remains Off
- If -ForceReboot:
- Optional countdown, stops transcript, Restart-Computer -Force
- Else:
- Stops transcript (if any), exits with accumulated exit code
-
Service lfsvc (Geolocation Service)
- StartupType: Automatic
- Status: Running
-
Policy override (HKLM)
- HKLM:\SOFTWARE\Policies\Microsoft\Windows\Location\DisableLocation = 0 (if present)
-
System configuration (HKLM)
- HKLM:\SYSTEM\CurrentControlSet\Services\lfsvc\Service\Configuration\Status = 1
-
User capability (HKCU)
- HKCU:\Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\location\Value = 'Allow'
Run PowerShell as Administrator.