Skip to content

Commit

Permalink
Removing Test-TCPPort (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkatyl authored Dec 11, 2024
1 parent 75b2f94 commit 277e483
Showing 1 changed file with 0 additions and 45 deletions.
45 changes: 0 additions & 45 deletions sysprep/activate_instance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,6 @@ function Activate-Instance {
# Apply the license key to the host.
& cscript //nologo $env:windir\system32\slmgr.vbs /ipk $license_key

if (-not (Test-TCPPort -Address $script:kms_server -Port $script:kms_server_port)) {
Write-Output 'Could not contact activation server. Will retry activation later.'
return
}

while ($retry_count -gt 0) {
Write-Output 'Activating instance...'
& cscript //nologo $env:windir\system32\slmgr.vbs /ato
Expand Down Expand Up @@ -315,46 +310,6 @@ function Verify-ActivationStatus {
return $active
}

function Test-TCPPort {
<#
.SYNOPSIS
Test TCP port on remote server
.DESCRIPTION
Use .Net Socket connection to connect to remote host and check if port is
open.
.PARAMETER host
Remote host you want to check TCP port for.
.PARAMETER port
TCP port number you want to check.
.RETURNS
Return bool. $true if server is reachable at tcp port $false is not.
#>
param (
[string]$Address,
[int]$Port
)

$status = $false
$socket = New-Object Net.Sockets.TcpClient
$connection = $socket.BeginConnect($Address, $Port, $null, $null)
$wait = $connection.AsyncWaitHandle.WaitOne(3000, $false)
if (!$wait) {
# Connection failed, timeout reached.
$socket.Close()
}
else {
$socket.EndConnect($connection) | Out-Null
if (!$?) {
Write-Host $error[0]
}
else {
$status = $true
}
$socket.Close()
}
return $status
}

if (Test-Path "$env:ProgramFiles\Google\Compute Engine\sysprep\byol_image") {
Write-Output 'Image imported into GCE via BYOL workflow, skipping GCE activation'
}
Expand Down

0 comments on commit 277e483

Please sign in to comment.