#Reset-GPOCache.ps1 #Alan dot Kaplan at VA dot GOV #3/17/2015 #Deletes local copies of GPO and forces a GPUpdate [long]$HKLM = 2147483650 $computer = $env:COMPUTERNAME Add-Type -assemblyname Microsoft.visualBasic $Computer = [Microsoft.VisualBasic.Interaction]::InputBox("Enter computer name to reset GPO cache", "Name", "$computer") if ($computer.length -eq 0){exit} if ((Test-Connection -Count 1 -ComputerName $computer -Quiet) -eq $False) { Write-Warning "$computer is offline" Exit } Try{ $WMIConnect = "\\"+$computer+"\root\Default:StdRegProv" $RegProv = [WMIClass]$WMIConnect }Catch{ Write-Warning $Error[0].Exception.Message Exit } $ShellFolders = "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" $AppData = ($RegProv.GetStringValue($HKLM, $ShellFolders, "Common AppData")).svalue $DeletePath = "\\"+$computer+"\"+$AppData.Replace(":","$")+"\Application Data\Microsoft\Group Policy\History\" c: write "Deleting cache files in $deletePath" Remove-Item -Path $DeletePath -Recurse -Force -ErrorAction SilentlyContinue $startup=[wmiclass]"Win32_ProcessStartup" #Create a process with process startup configuration to hide the window using [wmiclass] accelerator $startup.Properties['ShowWindow'].value=$False $command = "GPUpdate /force" Try{ $retval = ([wmiclass]"\\$Computer\ROOT\CIMV2:Win32_Process").create($command,$null,$Startup) Write "Ran `"$command`" on $computer" exit }Catch{ Write-Warning "Failed to run $command on $computer with error:" $errmsg = $Error[0].Exception.Message [regex]::Matches($errmsg,'Error.*').value }