66
77$domainUser = " $perf_domain \pkbadminuser"
88$domainName = " $perf_domain .local"
9+ $connectionVerified = $false
910
1011$passwordSecureString = (ConvertTo-SecureString - AsPlainText $perf_password - Force)
1112$nic = Get-NetIPAddress - AddressFamily IPv4 - InterfaceAlias ' E*'
@@ -17,10 +18,49 @@ Set-DnsClientServerAddress -InterfaceIndex $nic[0].ifIndex -ServerAddresses $dns
1718
1819$dns_server = Get-DnsClientServerAddress - InterfaceIndex $nic [0 ].ifIndex - AddressFamily IPv4
1920
21+ if (Test-Connection - ComputerName $DomainName - Count 1 - Quiet) {
22+ Write-Host ' Network connectivity to $DomainName is successful.'
23+ }
24+ else {
25+ Write-Host ' Cannot reach $DomainName via ICMP. Check DNS settings and network connectivity.'
26+ }
27+
28+ for ($i = 0 ; $i -lt 10 ; $i ++ ) {
29+ try {
30+ $test_connection = Test-NetConnection - ComputerName $DomainName - Port 135
31+ if ($test_connection.TcpTestSucceeded ) {
32+ Write-Host ' Network connectivity to $DomainName on port 135 is successful.'
33+ $connectionVerified = $true
34+ break
35+ }
36+ else {
37+ Write-Host ' Cannot reach $DomainName on port 135.'
38+ Start-Sleep - Seconds 30
39+ }
40+ }
41+ catch {
42+ Start-Sleep - Seconds 30
43+ }
44+ }
45+
46+ if (-not $connectionVerified ) {
47+ throw ' Cannot reach $DomainName.'
48+ }
49+
2050if ($dns_server.ServerAddresses -eq $dns_server_ip ) {
21- Write-Host " DNS Set. Joining $domainName Domain"
22- $credObject = New-Object System.Management.Automation.PSCredential ($domainUser , $passwordSecureString )
51+ for ($i = 0 ; $i -lt 3 ; $i ++ ) {
52+ try {
53+ Write-Host " DNS Set. Joining $domainName Domain"
54+ $credObject = New-Object System.Management.Automation.PSCredential ($domainUser , $passwordSecureString )
2355
24- Add-Computer - DomainName $domainName - credential $credObject
25- Write-Host ' Done'
56+ Add-Computer - DomainName $domainName - credential $credObject - ErrorAction Stop - PassThru
57+ Write-Host ' Done'
58+ break
59+ }
60+ catch {
61+ Write-Host ' Domain join test failed. Review the error details below:'
62+ Write-Error $_.Exception.Message
63+ Start-Sleep - Seconds 30
64+ }
65+ }
2666}
0 commit comments