Add lock_dir function that delete GWX folder
This commit is contained in:
parent
34a6fb45a0
commit
eecf96cf8b
1 changed files with 20 additions and 9 deletions
|
@ -22,6 +22,10 @@ $sheduledTasks=(
|
||||||
@{name = "refreshgwxcontent"; directory = "\Microsoft\Windows\Setup\GWX"}
|
@{name = "refreshgwxcontent"; directory = "\Microsoft\Windows\Setup\GWX"}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
$gwx_dirs=(
|
||||||
|
"$env:windir\system32\GWX",
|
||||||
|
)
|
||||||
|
|
||||||
# You need to modify this variable whith administrator group name
|
# You need to modify this variable whith administrator group name
|
||||||
# Here for French Windows this is Administrateurs
|
# Here for French Windows this is Administrateurs
|
||||||
$adminGroup="Administrateurs"
|
$adminGroup="Administrateurs"
|
||||||
|
@ -87,24 +91,31 @@ function hide_update() {
|
||||||
if (!$found){ Write-Host -ForegroundColor Red "Not found" }
|
if (!$found){ Write-Host -ForegroundColor Red "Not found" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#Remove GWX Files (test)
|
||||||
|
function lock_dir {
|
||||||
|
param([string]$dir)
|
||||||
|
Write-Host -ForegroundColor white "removing $dir content ... "
|
||||||
|
takeown /F "$dir" /R /D $yes 2>&1 | Out-Null
|
||||||
|
icacls "$dir" /C /grant $adminGroup":F" /T 2>&1 | Out-Null
|
||||||
|
Try{ Remove-Item $dir\* -Force -Recurse -ErrorAction SilentlyContinue}
|
||||||
|
Catch {Write-Host -ForegroundColor Red "Some files can't be deleted."}
|
||||||
|
}
|
||||||
|
|
||||||
Write-Host -Nonewline -ForegroundColor white "Searching for GWX process ... "
|
Write-Host -Nonewline -ForegroundColor white "Searching for GWX process ... "
|
||||||
if (Get-Process -name GWX -ErrorAction SilentlyContinue) {
|
if (Get-Process -name GWX -ErrorAction SilentlyContinue) {
|
||||||
Write-Host -ForegroundColor DarkGreen -NoNewLine "Running "
|
Write-Host -ForegroundColor DarkGreen -NoNewLine "Running "
|
||||||
Write-Host -Nonewline -ForegroundColor white "removing ... "
|
Write-Host -ForegroundColor white "removing ... "
|
||||||
Try {Stop-Process -name GWX -Force -ErrorAction SilentlyContinue}
|
Try {Stop-Process -name GWX -Force -ErrorAction SilentlyContinue}
|
||||||
Catch { Write-Host -ForegroundColor Red "Error"}
|
Catch { Write-Host -ForegroundColor Red "Error"}
|
||||||
}
|
}
|
||||||
else { Write-Host -ForegroundColor Yellow ("Not running")}
|
else { Write-Host -ForegroundColor Yellow ("Not running")}
|
||||||
|
|
||||||
#Remove GWX Files (test)
|
Write-Host -ForegroundColor white "`nRemoving and locking GWX folders ... "
|
||||||
takeown /F "$env:WINDIR\System32\GWX" /R /D $yes 2>&1 | Out-Null
|
$gwx_dirs | ForEach {
|
||||||
icacls "$env:WINDIR\System32\GWX" /C /grant $adminGroup":F" /T 2>&1 | Out-Null
|
lock_dir $_
|
||||||
Try{ Remove-Item $env:WINDIR\System32\GWX\* -Force -Recurse -ErrorAction SilentlyContinue}
|
}
|
||||||
Catch {Write-Host -ForegroundColor Red "Some files can't be deleted."}
|
|
||||||
#lock GWX directory
|
|
||||||
icacls "$env:WINDIR\System32\GWX" /deny Everyone:(CI)(OI)F 2>&1 | Out-Null
|
|
||||||
|
|
||||||
|
Write-Host -ForegroundColor white "`nRemoving and locking GWX folders ... "
|
||||||
|
|
||||||
Foreach($kbID in $kbIDs){
|
Foreach($kbID in $kbIDs){
|
||||||
$kbNum = $kbID.Replace("KB","")
|
$kbNum = $kbID.Replace("KB","")
|
||||||
|
|
Reference in a new issue