Last active
March 26, 2024 11:13
-
-
Save HighLibrarian/cef30247238aa57f3bb9cea5706746e7 to your computer and use it in GitHub Desktop.
Clear-GroupPolicyObjectCache.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
This script clears the local GPO cache for both user and device levels using remove-item commands. | |
.DESCRIPTION | |
This script clears the local GPO cache for both user and device levels using remove-item commands. | |
It stops any ongoing transcript, starts a new transcript for logging purposes, clears the GPO cache, | |
and then starts a new transcript for logging purposes. | |
.NOTES | |
Author: BDW | |
Date: 26/03/2024 | |
.LINK | |
.EXAMPLE | |
.\Clear-GpoCache.ps1 | |
#> | |
# Set transcript parameters | |
$TranscriptPath = "C:\ProgramData\Microsoft\IntuneManagementExtension\Logs\Remediations" | |
$TranscriptName = "Clear-GpoCache.log" | |
$FullTranscriptPath = Join-Path -Path $TranscriptPath -ChildPath $TranscriptName | |
# Create directory if it doesn't exist | |
if (-not (Test-Path -Path $TranscriptPath -PathType Container)) | |
{ | |
New-Item -Path $TranscriptPath -ItemType Directory -Force | Out-Null | |
} | |
# Stop any ongoing transcript | |
try | |
{ | |
Stop-Transcript | Out-Null | |
} | |
catch [System.InvalidOperationException] {} | |
# Start new transcript | |
Start-Transcript -Path $FullTranscriptPath -Append | |
# Clear GPO cache for user | |
Write-Output "Clearing user GPO cache..." | |
Remove-Item -Path "$env:windir\System32\GroupPolicy" -Recurse -Force -ErrorAction SilentlyContinue | |
# Clear GPO cache for device | |
Write-Output "Clearing device GPO cache..." | |
Remove-Item -Path "$env:windir\System32\GroupPolicyUsers" -Recurse -Force -ErrorAction SilentlyContinue | |
# End transcript | |
Stop-Transcript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment