5
5
[Parameter ()]
6
6
[switch ]$NoNetReporting ,
7
7
[Parameter ()]
8
- [switch ]$Cleanup
8
+ [switch ]$NoCleanup ,
9
+ [Parameter ()]
10
+ [switch ]$WithTools
9
11
)
10
12
11
13
$ErrorActionPreference = " Stop"
@@ -14,6 +16,10 @@ if (!(Test-Path "$PSScriptRoot\id_rsa.pub")) {
14
16
throw " Cannot find id_rsa.pub for SSH configuration"
15
17
}
16
18
19
+ if ($WithTools ) {
20
+ Read-Host - Prompt " Did you install PV tools manually?"
21
+ }
22
+
17
23
# Sometimes enabling updates will disrupt installation and rebooting.
18
24
# This is a temporary measure at most, but Microsoft makes disabling updates really difficult...
19
25
Write-Output " Disabling updates"
@@ -22,13 +28,10 @@ Stop-Service wuauserv
22
28
Set-Service wuauserv - StartupType Disabled
23
29
24
30
Write-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
28
32
if ($exitCode -ne 0 ) {
29
33
throw
30
34
}
31
- Remove-Item - Force $SSHDownloadPath - ErrorAction SilentlyContinue
32
35
Copy-Item " $PSScriptRoot \id_rsa.pub" " $env: ProgramData \ssh\administrators_authorized_keys" - Force
33
36
icacls.exe " $env: ProgramData \ssh\administrators_authorized_keys" / inheritance:r / grant " Administrators:F" / grant " SYSTEM:F"
34
37
if ($LASTEXITCODE -ne 0 ) {
@@ -37,15 +40,18 @@ if ($LASTEXITCODE -ne 0) {
37
40
New-NetFirewallRule - Action Allow - Program " $env: ProgramFiles \OpenSSH\sshd.exe" - Direction Inbound - Protocol TCP - LocalPort 22 - DisplayName sshd
38
41
39
42
Write-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
43
44
if ($exitCode -ne 0 ) {
44
45
throw
45
46
}
46
- Remove-Item - Force $GitDownloadPath - ErrorAction SilentlyContinue
47
47
Set-ItemProperty - Path " HKLM:\SOFTWARE\OpenSSH" - Name DefaultShell - Type String - Value " $env: ProgramFiles \Git\bin\bash.exe" - Force
48
48
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
+
49
55
if (! $NoNetReporting ) {
50
56
Write-Output " Installing network reporting script"
51
57
Copy-Item " $PSScriptRoot \netreport.ps1" " $env: SystemDrive \" - Force
@@ -56,23 +62,28 @@ if (!$NoNetReporting) {
56
62
Register-ScheduledTask - InputObject $task - TaskName " XCP-ng Test Network Report"
57
63
}
58
64
59
- if ($Cleanup ) {
65
+ if (! $NoCleanup ) {
60
66
Read-Host - Prompt " Unplug Internet, run Disk Cleanup and continue"
67
+ # You should check at least "Temporary files" in Disk Cleanup
61
68
62
69
Write-Output " Cleaning up component store"
63
70
dism.exe / Online / Cleanup- Image / StartComponentCleanup / ResetBase
64
71
65
72
Write-Output " Cleaning up SoftwareDistribution"
66
- Stop-Service wuauserv, BITS - ErrorAction SilentlyContinue
73
+ Stop-Service wuauserv, BITS
67
74
Remove-Item - Recurse - Force - ErrorAction SilentlyContinue " $env: windir \SoftwareDistribution\Download\*"
68
75
69
76
Write-Output " Cleaning up Defender signatures"
70
77
& " $env: ProgramFiles \Windows Defender\MpCmdRun.exe" - RemoveDefinitions - All
71
-
72
- Write-Output " Optimizing system drive"
73
- defrag.exe $env: SystemDrive / O
74
78
}
75
79
76
80
Write-Output " Resealing"
77
81
Stop-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