@@ -8,33 +8,32 @@ Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase
88
99Write-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"
0 commit comments