55 [Parameter ()]
66 [switch ]$NoNetReporting ,
77 [Parameter ()]
8- [switch ]$Cleanup
8+ [switch ]$NoCleanup ,
9+ [Parameter ()]
10+ [switch ]$WithTools
911)
1012
1113$ErrorActionPreference = " Stop"
@@ -14,6 +16,10 @@ if (!(Test-Path "$PSScriptRoot\id_rsa.pub")) {
1416 throw " Cannot find id_rsa.pub for SSH configuration"
1517}
1618
19+ if ($WithTools ) {
20+ Read-Host - Prompt " Did you install PV tools manually?"
21+ }
22+
1723# Sometimes enabling updates will disrupt installation and rebooting.
1824# This is a temporary measure at most, but Microsoft makes disabling updates really difficult...
1925Write-Output " Disabling updates"
@@ -22,13 +28,10 @@ Stop-Service wuauserv
2228Set-Service wuauserv - StartupType Disabled
2329
2430Write-Output " Installing SSH"
25- $SSHDownloadPath = " $env: TEMP \OpenSSH-Win64-v9.8.1.0.msi"
26- Invoke-WebRequest - UseBasicParsing - Uri " https://github.com/PowerShell/Win32-OpenSSH/releases/download/v9.8.1.0p1-Preview/OpenSSH-Win64-v9.8.1.0.msi" - OutFile $SSHDownloadPath
27- $exitCode = (Start-Process - Wait msiexec.exe - ArgumentList " /i" , $SSHDownloadPath , " /passive" , " /norestart" - PassThru).ExitCode
31+ $exitCode = (Start-Process - Wait msiexec.exe - ArgumentList " /i `" $PSScriptRoot \OpenSSH-Win64-v9.8.3.0.msi`" /passive /norestart" - PassThru).ExitCode
2832if ($exitCode -ne 0 ) {
2933 throw
3034}
31- Remove-Item - Force $SSHDownloadPath - ErrorAction SilentlyContinue
3235Copy-Item " $PSScriptRoot \id_rsa.pub" " $env: ProgramData \ssh\administrators_authorized_keys" - Force
3336icacls.exe " $env: ProgramData \ssh\administrators_authorized_keys" / inheritance:r / grant " Administrators:F" / grant " SYSTEM:F"
3437if ($LASTEXITCODE -ne 0 ) {
@@ -37,15 +40,18 @@ if ($LASTEXITCODE -ne 0) {
3740New-NetFirewallRule - Action Allow - Program " $env: ProgramFiles \OpenSSH\sshd.exe" - Direction Inbound - Protocol TCP - LocalPort 22 - DisplayName sshd
3841
3942Write-Output " Installing Git Bash"
40- $GitDownloadPath = " $env: TEMP \Git-2.47.1-64-bit.exe"
41- Invoke-WebRequest - UseBasicParsing - Uri " https://github.com/git-for-windows/git/releases/download/v2.47.1.windows.1/Git-2.47.1-64-bit.exe" - OutFile $GitDownloadPath
42- $exitCode = (Start-Process - Wait $GitDownloadPath - ArgumentList " /silent" - PassThru).ExitCode
43+ $exitCode = (Start-Process - Wait " $PSScriptRoot \Git-2.49.0-64-bit.exe" - ArgumentList " /silent" - PassThru).ExitCode
4344if ($exitCode -ne 0 ) {
4445 throw
4546}
46- Remove-Item - Force $GitDownloadPath - ErrorAction SilentlyContinue
4747Set-ItemProperty - Path " HKLM:\SOFTWARE\OpenSSH" - Name DefaultShell - Type String - Value " $env: ProgramFiles \Git\bin\bash.exe" - Force
4848
49+ Write-Output " Disabling automatic disk optimization"
50+ schtasks / change / disable / tn " \Microsoft\Windows\Defrag\ScheduledDefrag"
51+ if ($exitCode -ne 0 ) {
52+ throw
53+ }
54+
4955if (! $NoNetReporting ) {
5056 Write-Output " Installing network reporting script"
5157 Copy-Item " $PSScriptRoot \netreport.ps1" " $env: SystemDrive \" - Force
@@ -56,23 +62,28 @@ if (!$NoNetReporting) {
5662 Register-ScheduledTask - InputObject $task - TaskName " XCP-ng Test Network Report"
5763}
5864
59- if ($Cleanup ) {
65+ if (! $NoCleanup ) {
6066 Read-Host - Prompt " Unplug Internet, run Disk Cleanup and continue"
67+ # You should check at least "Temporary files" in Disk Cleanup
6168
6269 Write-Output " Cleaning up component store"
6370 dism.exe / Online / Cleanup- Image / StartComponentCleanup / ResetBase
6471
6572 Write-Output " Cleaning up SoftwareDistribution"
66- Stop-Service wuauserv, BITS - ErrorAction SilentlyContinue
73+ Stop-Service wuauserv, BITS
6774 Remove-Item - Recurse - Force - ErrorAction SilentlyContinue " $env: windir \SoftwareDistribution\Download\*"
6875
6976 Write-Output " Cleaning up Defender signatures"
7077 & " $env: ProgramFiles \Windows Defender\MpCmdRun.exe" - RemoveDefinitions - All
71-
72- Write-Output " Optimizing system drive"
73- defrag.exe $env: SystemDrive / O
7478}
7579
7680Write-Output " Resealing"
7781Stop-Process - Name sysprep - ErrorAction SilentlyContinue
78- & " $env: windir \System32\Sysprep\sysprep.exe" / generalize / oobe / shutdown / unattend:$PSScriptRoot \unattend.xml
82+ if ($WithTools ) {
83+ # WS2025 eval only allows 1 rearm, save this for later
84+ Set-ItemProperty - Path " HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" - Name SkipRearm - Type DWord - Value 1
85+ & " $env: windir \System32\Sysprep\sysprep.exe" " /generalize" " /oobe" " /shutdown" " /unattend:$PSScriptRoot \unattend-persisthw.xml"
86+ }
87+ else {
88+ & " $env: windir \System32\Sysprep\sysprep.exe" " /generalize" " /oobe" " /shutdown" " /unattend:$PSScriptRoot \unattend.xml"
89+ }
0 commit comments