Better gpUpdate
This commit is contained in:
parent
c0e982c42f
commit
4671387d85
|
|
@ -12,7 +12,7 @@
|
||||||
RootModule = 'Get-PC.psm1'
|
RootModule = 'Get-PC.psm1'
|
||||||
|
|
||||||
# Version number of this module.
|
# Version number of this module.
|
||||||
ModuleVersion = '0.4.18'
|
ModuleVersion = '0.4.19'
|
||||||
|
|
||||||
# Supported PSEditions
|
# Supported PSEditions
|
||||||
# CompatiblePSEditions = @()
|
# CompatiblePSEditions = @()
|
||||||
|
|
|
||||||
|
|
@ -4,22 +4,33 @@
|
||||||
|
|
||||||
#Looks on the machine and tries to access the group policy.
|
#Looks on the machine and tries to access the group policy.
|
||||||
try {
|
try {
|
||||||
$oldPolicy = Get-ChildItem \\$ComputerName\c$\Windows\System32\GroupPolicy\Machine
|
$oldPolicy = Get-ChildItem \\$ComputerName\c$\Windows\System32\GroupPolicy
|
||||||
|
$oldPolicyUsers = Get-ChildItem \\$ComputerName\c$\Windows\System32\GroupPolicyUsers
|
||||||
}
|
}
|
||||||
catch{
|
catch{
|
||||||
Write-Host "Failed to access group policy" -ForegroundColor Red
|
Write-Host "Failed to access group policy" -ForegroundColor Red
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
#Deletes the old group policy. Reasoning is that if we are running this there is something very wrong and we will be immediately re-applying it.
|
#Deletes the old group policy. Reasoning is that if we are running this there is something very wrong and we will be immediately re-applying it.
|
||||||
if(!$oldPolicy){
|
if(!$oldPolicy -and !$oldPolicyUsers){
|
||||||
Write-Host "No group policy found on machine" -ForegroundColor Red
|
Write-Host "No group policy found on machine" -ForegroundColor Red
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
Remove-Item $oldPolicy
|
Remove-Item $oldPolicy -ErrorAction 'SilentlyContinue'
|
||||||
|
Remove-Item $oldPolicyUsers -ErrorAction 'SilentlyContinue'
|
||||||
}
|
}
|
||||||
|
|
||||||
#Attempts to remotely re-apply group policy. If this fails I let the user know so they can go to the computer and manually do it.
|
#Attempts to remotely re-apply group policy. If this fails I let the user know so they can go to the computer and manually do it.
|
||||||
try {
|
try {
|
||||||
Invoke-Command -ComputerName $ComputerName -SessionOption (New-PSSessionOption -NoMachineProfile) -ScriptBlock {& gpupdate /force}
|
Invoke-Command -ComputerName $ComputerName -SessionOption (New-PSSessionOption -NoMachineProfile) -ScriptBlock {
|
||||||
|
@(
|
||||||
|
"HKLM\Software\Policies\Microsoft",
|
||||||
|
"HKCU\Software\Policies\Microsoft",
|
||||||
|
"HKCU\Software\Microsoft\Windows\CurrentVersion\Group Policy Objects",
|
||||||
|
"HKCU\Software\Microsoft\Windows\CurrentVersion\Policies"
|
||||||
|
) | ForEach-Object { Remove-Item -Recurse "Registry::$_" }
|
||||||
|
& gpupdate /force
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch{
|
catch{
|
||||||
Write-Host "Unable to reapply group policy" -ForegroundColor Red
|
Write-Host "Unable to reapply group policy" -ForegroundColor Red
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
Patch 2025-3-20
|
||||||
|
-Update GPUpdate is now more robust by clearing more files and registry keys
|
||||||
|
|
||||||
Patch 2025-3-14
|
Patch 2025-3-14
|
||||||
-Fix Queries Spark! by asset tag rather than hostname to also hit in stock workstations
|
-Fix Queries Spark! by asset tag rather than hostname to also hit in stock workstations
|
||||||
-Add Elo monitor ports to -devices
|
-Add Elo monitor ports to -devices
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue