[Windows] Update Finalize-VM (#4791)

This commit is contained in:
Nikolay Frolov
2021-12-22 17:42:54 +03:00
committed by GitHub
parent 986530d6bb
commit 35c775a852
4 changed files with 18 additions and 16 deletions

View File

@@ -8,33 +8,32 @@ Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase
Write-Host "Clean up various directories" Write-Host "Clean up various directories"
@( @(
"C:\\Recovery", "$env:SystemDrive\Recovery",
"$env:windir\\logs", "$env:SystemRoot\logs",
"$env:windir\\winsxs\\manifestcache", "$env:SystemRoot\winsxs\manifestcache",
"$env:windir\\Temp", "$env:SystemRoot\Temp",
"$env:TEMP" "$env:TEMP"
) | ForEach-Object { ) | ForEach-Object {
if (Test-Path $_) { if (Test-Path $_) {
Write-Host "Removing $_" Write-Host "Removing $_"
try { cmd /c "takeown /d Y /R /f $_ 2>&1" | Out-Null
Takeown /d Y /R /f $_ | Out-Null cmd /c "icacls $_ /grant:r administrators:f /t /c /q 2>&1" | Out-Null
Icacls $_ /GRANT:r administrators:F /T /c /q 2>&1 | Out-Null Remove-Item $_ -Recurse -Force -ErrorAction SilentlyContinue | Out-Null
Remove-Item $_ -Recurse -Force | Out-Null
}
catch { $global:error.RemoveAt(0) }
} }
} }
$winInstallDir = "$env:windir\\Installer" $winInstallDir = "$env:SystemRoot\Installer"
New-Item -Path $winInstallDir -ItemType Directory -Force New-Item -Path $winInstallDir -ItemType Directory -Force | Out-Null
# Remove AllUsersAllHosts profile # Remove AllUsersAllHosts profile
Remove-Item $profile.AllUsersAllHosts -Force Remove-Item $profile.AllUsersAllHosts -Force -ErrorAction SilentlyContinue | Out-Null
# Clean yarn and npm cache # Clean yarn and npm cache
yarn cache clean cmd /c "yarn cache clean 2>&1" | Out-Null
npm cache clean --force cmd /c "npm cache clean --force 2>&1" | Out-Null
# allow msi to write to temp folder # allow msi to write to temp folder
# see https://github.com/actions/virtual-environments/issues/1704 # see https://github.com/actions/virtual-environments/issues/1704
icacls "C:\Windows\Temp" /q /c /t /grant Users:F /T cmd /c "icacls $env:SystemRoot\Temp /grant Users:f /t /c /q 2>&1" | Out-Null
Write-Host "Finalize-VM.ps1 - completed"

View File

@@ -295,6 +295,7 @@
}, },
{ {
"type": "powershell", "type": "powershell",
"skip_clean": true,
"scripts": [ "scripts": [
"{{ template_dir }}/scripts/Installers/Finalize-VM.ps1" "{{ template_dir }}/scripts/Installers/Finalize-VM.ps1"
] ]

View File

@@ -307,6 +307,7 @@
}, },
{ {
"type": "powershell", "type": "powershell",
"skip_clean": true,
"scripts": [ "scripts": [
"{{ template_dir }}/scripts/Installers/Run-NGen.ps1", "{{ template_dir }}/scripts/Installers/Run-NGen.ps1",
"{{ template_dir }}/scripts/Installers/Finalize-VM.ps1" "{{ template_dir }}/scripts/Installers/Finalize-VM.ps1"

View File

@@ -294,6 +294,7 @@
}, },
{ {
"type": "powershell", "type": "powershell",
"skip_clean": true,
"scripts": [ "scripts": [
"{{ template_dir }}/scripts/Installers/Run-NGen.ps1", "{{ template_dir }}/scripts/Installers/Run-NGen.ps1",
"{{ template_dir }}/scripts/Installers/Finalize-VM.ps1" "{{ template_dir }}/scripts/Installers/Finalize-VM.ps1"