diff --git a/template/Prepare-WinBuild2022.ps1 b/template/Prepare-WinBuild2022.ps1 index 36e40ef..ab0ee64 100644 --- a/template/Prepare-WinBuild2022.ps1 +++ b/template/Prepare-WinBuild2022.ps1 @@ -163,7 +163,19 @@ param( Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' -$ProgressPreference = 'SilentlyContinue' # suppress Write-Progress (Test-NetConnection, IWR, etc.) +$ProgressPreference = 'SilentlyContinue' # suppress Write-Progress (IWR, etc.) + +function Test-TcpPort { + param([string]$ComputerName, [int]$Port, [int]$TimeoutMs = 3000) + try { + $tcp = [System.Net.Sockets.TcpClient]::new() + $ar = $tcp.BeginConnect($ComputerName, $Port, $null, $null) + $ok = $ar.AsyncWaitHandle.WaitOne($TimeoutMs, $false) + $connected = $ok -and $tcp.Connected + $tcp.Close() + return $connected + } catch { return $false } +} # ── Locate vmrun.exe ────────────────────────────────────────────────────────── $vmrunCandidates = @( @@ -247,8 +259,7 @@ Write-Host "[Prepare] Waiting for WinRM on $VMIPAddress`:5986 (timeout ${winrmTi $winrmDeadline = [datetime]::UtcNow.AddSeconds($winrmTimeoutSec) $winrmReady = $false while ([datetime]::UtcNow -lt $winrmDeadline) { - if (Test-NetConnection -ComputerName $VMIPAddress -Port 5986 ` - -InformationLevel Quiet -WarningAction SilentlyContinue -ErrorAction SilentlyContinue) { + if (Test-TcpPort -ComputerName $VMIPAddress -Port 5986 -TimeoutMs 5000) { $winrmReady = $true; break } Start-Sleep -Seconds 5 diff --git a/template/Prepare-WinBuild2025.ps1 b/template/Prepare-WinBuild2025.ps1 index 4623471..f74e560 100644 --- a/template/Prepare-WinBuild2025.ps1 +++ b/template/Prepare-WinBuild2025.ps1 @@ -163,7 +163,19 @@ param( Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' -$ProgressPreference = 'SilentlyContinue' # suppress Write-Progress (Test-NetConnection, IWR, etc.) +$ProgressPreference = 'SilentlyContinue' # suppress Write-Progress (IWR, etc.) + +function Test-TcpPort { + param([string]$ComputerName, [int]$Port, [int]$TimeoutMs = 3000) + try { + $tcp = [System.Net.Sockets.TcpClient]::new() + $ar = $tcp.BeginConnect($ComputerName, $Port, $null, $null) + $ok = $ar.AsyncWaitHandle.WaitOne($TimeoutMs, $false) + $connected = $ok -and $tcp.Connected + $tcp.Close() + return $connected + } catch { return $false } +} # ── Locate vmrun.exe ────────────────────────────────────────────────────────── $vmrunCandidates = @( @@ -247,8 +259,7 @@ Write-Host "[Prepare] Waiting for WinRM on $VMIPAddress`:5986 (timeout ${winrmTi $winrmDeadline = [datetime]::UtcNow.AddSeconds($winrmTimeoutSec) $winrmReady = $false while ([datetime]::UtcNow -lt $winrmDeadline) { - if (Test-NetConnection -ComputerName $VMIPAddress -Port 5986 ` - -InformationLevel Quiet -WarningAction SilentlyContinue -ErrorAction SilentlyContinue) { + if (Test-TcpPort -ComputerName $VMIPAddress -Port 5986 -TimeoutMs 5000) { $winrmReady = $true; break } Start-Sleep -Seconds 5