$SshExe = 'C:\Windows\System32\OpenSSH\ssh.exe'
$SshTarget = 'INTRANET\sysadmin@192.168.0.6'

# Create a test script on AD2
$testScript = @'
try {
    $r = Invoke-WebRequest -Uri "http://localhost:3000/api/stats" -UseBasicParsing -TimeoutSec 5
    Write-Output "STATUS: $($r.StatusCode)"
    Write-Output "CONTENT: $($r.Content.Substring(0, [Math]::Min(200, $r.Content.Length)))"
} catch {
    Write-Output "ERROR: $($_.Exception.Message)"
}
'@

# Write test script to AD2
$testScript | & $SshExe $SshTarget 'powershell -Command "Set-Content -Path C:\Shares\testdatadb\test-web.ps1 -Value (Get-Content -Raw -Path -)"'

# Actually, simpler - just run inline
& $SshExe $SshTarget 'powershell -NoProfile -ExecutionPolicy Bypass -Command "try { $r = Invoke-WebRequest -Uri http://localhost:3000/ -UseBasicParsing -TimeoutSec 5; Write-Output STATUS:$($r.StatusCode) } catch { Write-Output ERROR:$($_.Exception.Message) }"'
