Skip to content

Commit 35c775a

Browse files
[Windows] Update Finalize-VM (#4791)
1 parent 986530d commit 35c775a

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

images/win/scripts/Installers/Finalize-VM.ps1

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,32 @@ Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase
88

99
Write-Host "Clean up various directories"
1010
@(
11-
"C:\\Recovery",
12-
"$env:windir\\logs",
13-
"$env:windir\\winsxs\\manifestcache",
14-
"$env:windir\\Temp",
11+
"$env:SystemDrive\Recovery",
12+
"$env:SystemRoot\logs",
13+
"$env:SystemRoot\winsxs\manifestcache",
14+
"$env:SystemRoot\Temp",
1515
"$env:TEMP"
1616
) | ForEach-Object {
1717
if (Test-Path $_) {
1818
Write-Host "Removing $_"
19-
try {
20-
Takeown /d Y /R /f $_ | Out-Null
21-
Icacls $_ /GRANT:r administrators:F /T /c /q 2>&1 | Out-Null
22-
Remove-Item $_ -Recurse -Force | Out-Null
23-
}
24-
catch { $global:error.RemoveAt(0) }
19+
cmd /c "takeown /d Y /R /f $_ 2>&1" | Out-Null
20+
cmd /c "icacls $_ /grant:r administrators:f /t /c /q 2>&1" | Out-Null
21+
Remove-Item $_ -Recurse -Force -ErrorAction SilentlyContinue | Out-Null
2522
}
2623
}
2724

28-
$winInstallDir = "$env:windir\\Installer"
29-
New-Item -Path $winInstallDir -ItemType Directory -Force
25+
$winInstallDir = "$env:SystemRoot\Installer"
26+
New-Item -Path $winInstallDir -ItemType Directory -Force | Out-Null
3027

3128
# Remove AllUsersAllHosts profile
32-
Remove-Item $profile.AllUsersAllHosts -Force
29+
Remove-Item $profile.AllUsersAllHosts -Force -ErrorAction SilentlyContinue | Out-Null
3330

3431
# Clean yarn and npm cache
35-
yarn cache clean
36-
npm cache clean --force
32+
cmd /c "yarn cache clean 2>&1" | Out-Null
33+
cmd /c "npm cache clean --force 2>&1" | Out-Null
3734

3835
# allow msi to write to temp folder
3936
# see https://github.com/actions/virtual-environments/issues/1704
40-
icacls "C:\Windows\Temp" /q /c /t /grant Users:F /T
37+
cmd /c "icacls $env:SystemRoot\Temp /grant Users:f /t /c /q 2>&1" | Out-Null
38+
39+
Write-Host "Finalize-VM.ps1 - completed"

images/win/windows2016.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@
295295
},
296296
{
297297
"type": "powershell",
298+
"skip_clean": true,
298299
"scripts": [
299300
"{{ template_dir }}/scripts/Installers/Finalize-VM.ps1"
300301
]

images/win/windows2019.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@
307307
},
308308
{
309309
"type": "powershell",
310+
"skip_clean": true,
310311
"scripts": [
311312
"{{ template_dir }}/scripts/Installers/Run-NGen.ps1",
312313
"{{ template_dir }}/scripts/Installers/Finalize-VM.ps1"

images/win/windows2022.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@
294294
},
295295
{
296296
"type": "powershell",
297+
"skip_clean": true,
297298
"scripts": [
298299
"{{ template_dir }}/scripts/Installers/Run-NGen.ps1",
299300
"{{ template_dir }}/scripts/Installers/Finalize-VM.ps1"

0 commit comments

Comments
 (0)