#Requires -Version 5.1 <# .SYNOPSIS Quick test script for WinRM HTTPS connections to shopfloor PCs .DESCRIPTION This script tests WinRM HTTPS connectivity to shopfloor PCs. Run this from your management computer to verify deployed PCs are working. .PARAMETER ComputerName Hostname of the PC to test (without domain suffix) Example: g9kn7pz3esf .PARAMETER SkipCertificateCheck Skip SSL certificate validation (use for self-signed certs) .PARAMETER Interactive Open an interactive PowerShell session after successful test .EXAMPLE # Basic test .\Test-ShopfloorPC.ps1 -ComputerName g9kn7pz3esf .EXAMPLE # Test and open interactive session .\Test-ShopfloorPC.ps1 -ComputerName g9kn7pz3esf -Interactive .EXAMPLE # Test with certificate check skipped .\Test-ShopfloorPC.ps1 -ComputerName g9kn7pz3esf -SkipCertificateCheck .NOTES Author: System Administrator Date: 2025-10-17 Domain: logon.ds.ge.com Port: 5986 (WinRM HTTPS) #> param( [Parameter(Mandatory=$true, Position=0)] [string]$ComputerName, [Parameter(Mandatory=$false)] [switch]$SkipCertificateCheck, [Parameter(Mandatory=$false)] [switch]$Interactive ) # Configuration $Domain = "logon.ds.ge.com" $Port = 5986 # Remove domain suffix if user included it $ComputerName = $ComputerName -replace "\.$Domain$", "" # Construct FQDN $FQDN = "$ComputerName.$Domain" # Banner Write-Host "" Write-Host "╔══════════════════════════════════════════════════════════════╗" -ForegroundColor Cyan Write-Host "║ WinRM HTTPS Connection Test - Shopfloor PC ║" -ForegroundColor Cyan Write-Host "╚══════════════════════════════════════════════════════════════╝" -ForegroundColor Cyan Write-Host "" Write-Host "Target PC: $FQDN" -ForegroundColor White Write-Host "Port: $Port" -ForegroundColor White Write-Host "Time: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')" -ForegroundColor White Write-Host "" # Session options $sessionOption = $null if ($SkipCertificateCheck) { Write-Host "[INFO] Skipping SSL certificate validation" -ForegroundColor Yellow $sessionOption = New-PSSessionOption -SkipCACheck -SkipCNCheck Write-Host "" } # Test 1: Basic network connectivity Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray Write-Host "TEST 1: Network Connectivity" -ForegroundColor Yellow Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray try { $ping = Test-Connection $FQDN -Count 2 -ErrorAction Stop $avgTime = ($ping.ResponseTime | Measure-Object -Average).Average Write-Host "✓ PC is reachable" -ForegroundColor Green Write-Host " Average response time: $([math]::Round($avgTime, 2))ms" -ForegroundColor Gray } catch { Write-Host "✗ Cannot reach PC" -ForegroundColor Red Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red Write-Host "" Write-Host "Troubleshooting:" -ForegroundColor Yellow Write-Host " • Verify PC is powered on" -ForegroundColor Gray Write-Host " • Check network connectivity" -ForegroundColor Gray Write-Host " • Verify hostname spelling" -ForegroundColor Gray exit 1 } # Test 2: DNS resolution Write-Host "" Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray Write-Host "TEST 2: DNS Resolution" -ForegroundColor Yellow Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray try { $dns = Resolve-DnsName $FQDN -ErrorAction Stop | Where-Object {$_.Type -eq 'A'} Write-Host "✓ DNS resolution successful" -ForegroundColor Green Write-Host " IP Address: $($dns.IPAddress)" -ForegroundColor Gray } catch { Write-Host "✗ DNS resolution failed" -ForegroundColor Red Write-Host " Using hostname from ping result" -ForegroundColor Yellow } # Test 3: Port connectivity Write-Host "" Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray Write-Host "TEST 3: Port $Port Connectivity" -ForegroundColor Yellow Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray try { $portTest = Test-NetConnection -ComputerName $FQDN -Port $Port -WarningAction SilentlyContinue -ErrorAction Stop if ($portTest.TcpTestSucceeded) { Write-Host "✓ Port $Port is open and accepting connections" -ForegroundColor Green } else { Write-Host "✗ Port $Port is closed or filtered" -ForegroundColor Red Write-Host "" Write-Host "Troubleshooting:" -ForegroundColor Yellow Write-Host " • Verify WinRM HTTPS deployment completed successfully" -ForegroundColor Gray Write-Host " • Check firewall rules on target PC" -ForegroundColor Gray Write-Host " • Verify WinRM service is running" -ForegroundColor Gray exit 1 } } catch { Write-Host "✗ Cannot test port connectivity" -ForegroundColor Red Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red } # Test 4: WinRM HTTPS connectivity Write-Host "" Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray Write-Host "TEST 4: WinRM HTTPS Service" -ForegroundColor Yellow Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray try { $testParams = @{ ComputerName = $FQDN UseSSL = $true Port = $Port ErrorAction = 'Stop' } if ($sessionOption) { $testParams.SessionOption = $sessionOption } $wsmanTest = Test-WSMan @testParams Write-Host "✓ WinRM HTTPS is responding" -ForegroundColor Green Write-Host " Product: $($wsmanTest.ProductVendor)" -ForegroundColor Gray Write-Host " Version: $($wsmanTest.ProductVersion)" -ForegroundColor Gray Write-Host " Protocol: $($wsmanTest.ProtocolVersion)" -ForegroundColor Gray } catch { Write-Host "✗ WinRM HTTPS not responding" -ForegroundColor Red Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red Write-Host "" if ($_.Exception.Message -like "*certificate*" -and -not $SkipCertificateCheck) { Write-Host "Tip: This looks like a certificate trust issue." -ForegroundColor Yellow Write-Host " Try running with -SkipCertificateCheck flag:" -ForegroundColor Yellow Write-Host " .\Test-ShopfloorPC.ps1 -ComputerName $ComputerName -SkipCertificateCheck" -ForegroundColor White } exit 1 } # Test 5: Authenticated connection Write-Host "" Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray Write-Host "TEST 5: Authenticated Remote Command" -ForegroundColor Yellow Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray Write-Host "" Write-Host "Enter credentials for $FQDN" -ForegroundColor Cyan $cred = Get-Credential -Message "Enter credentials for $FQDN" if (-not $cred) { Write-Host "" Write-Host "✗ No credentials provided" -ForegroundColor Red exit 1 } Write-Host "" Write-Host "Executing remote command..." -ForegroundColor Gray try { $invokeParams = @{ ComputerName = $FQDN Credential = $cred UseSSL = $true Port = $Port ErrorAction = 'Stop' ScriptBlock = { [PSCustomObject]@{ Hostname = $env:COMPUTERNAME IPAddress = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object {$_.IPAddress -notlike "127.*" -and $_.IPAddress -notlike "169.254.*"} | Select-Object -First 1).IPAddress WinRMStatus = (Get-Service WinRM).Status OSVersion = (Get-CimInstance Win32_OperatingSystem).Caption Uptime = (Get-Date) - (Get-CimInstance Win32_OperatingSystem).LastBootUpTime FreeMemoryGB = [math]::Round((Get-CimInstance Win32_OperatingSystem).FreePhysicalMemory / 1MB, 2) } } } if ($sessionOption) { $invokeParams.SessionOption = $sessionOption } $remoteInfo = Invoke-Command @invokeParams Write-Host "✓ Remote command executed successfully" -ForegroundColor Green Write-Host "" Write-Host "╔══════════════════════════════════════════════════════════════╗" -ForegroundColor Green Write-Host "║ REMOTE COMPUTER INFORMATION ║" -ForegroundColor Green Write-Host "╚══════════════════════════════════════════════════════════════╝" -ForegroundColor Green Write-Host "" Write-Host " Hostname: $($remoteInfo.Hostname)" -ForegroundColor White Write-Host " IP Address: $($remoteInfo.IPAddress)" -ForegroundColor White Write-Host " OS Version: $($remoteInfo.OSVersion)" -ForegroundColor White Write-Host " WinRM Status: $($remoteInfo.WinRMStatus)" -ForegroundColor White Write-Host " Uptime: $($remoteInfo.Uptime.Days) days, $($remoteInfo.Uptime.Hours) hours, $($remoteInfo.Uptime.Minutes) minutes" -ForegroundColor White Write-Host " Free Memory: $($remoteInfo.FreeMemoryGB) GB" -ForegroundColor White Write-Host "" } catch { Write-Host "✗ Authentication or remote command failed" -ForegroundColor Red Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red Write-Host "" Write-Host "Troubleshooting:" -ForegroundColor Yellow Write-Host " • Verify username and password are correct" -ForegroundColor Gray Write-Host " • Try format: DOMAIN\username or .\localadmin" -ForegroundColor Gray Write-Host " • Ensure user has Administrator rights on target PC" -ForegroundColor Gray exit 1 } # Success summary Write-Host "" Write-Host "╔══════════════════════════════════════════════════════════════╗" -ForegroundColor Cyan Write-Host "║ TEST SUCCESSFUL ║" -ForegroundColor Cyan Write-Host "╚══════════════════════════════════════════════════════════════╝" -ForegroundColor Cyan Write-Host "" Write-Host "All tests passed! WinRM HTTPS is configured correctly." -ForegroundColor Green Write-Host "" # Interactive mode if ($Interactive) { Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray Write-Host "Opening interactive session..." -ForegroundColor Yellow Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor Gray Write-Host "" Write-Host "Type 'Exit-PSSession' or 'exit' to close the session" -ForegroundColor Gray Write-Host "" $sessionParams = @{ ComputerName = $FQDN Credential = $cred UseSSL = $true Port = $Port } if ($sessionOption) { $sessionParams.SessionOption = $sessionOption } Enter-PSSession @sessionParams } else { Write-Host "Quick Connection Commands:" -ForegroundColor Yellow Write-Host "" Write-Host " # Interactive session" -ForegroundColor Gray if ($SkipCertificateCheck) { Write-Host " `$sessionOption = New-PSSessionOption -SkipCACheck -SkipCNCheck" -ForegroundColor White Write-Host " Enter-PSSession -ComputerName $FQDN -Credential `$cred -UseSSL -Port $Port -SessionOption `$sessionOption" -ForegroundColor White } else { Write-Host " Enter-PSSession -ComputerName $FQDN -Credential `$cred -UseSSL -Port $Port" -ForegroundColor White } Write-Host "" Write-Host " # Or run this script with -Interactive flag:" -ForegroundColor Gray Write-Host " .\Test-ShopfloorPC.ps1 -ComputerName $ComputerName -Interactive$(if($SkipCertificateCheck){' -SkipCertificateCheck'})" -ForegroundColor White Write-Host "" }