POWERSHELL 32
Curl-test.ps1 By allan on 21st September 2026 11:43:43 AM
  1. $location = @('B0', 'CVF', 'OOV', 'openlayers', 'TRA', 'VM', 'WH1', 'rest')
  2. $baseUrl = 'https://geocloudtest.vd.dk/'
  3. $logFile = 'C:\Temp\curl-test.log'
  4. $failures = @()
  5.  
  6. function Log-Message {
  7.     param([string]$Message)
  8.     $timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
  9.     $line = "$timestamp $Message"
  10.     Write-Output $line
  11.     Add-Content -Path $logFile -Value $line
  12. }
  13.  
  14. if (-not (Test-Path (Split-Path $logFile -Parent))) {
  15.     New-Item -ItemType Directory -Path (Split-Path $logFile -Parent) -Force | Out-Null
  16. }
  17.  
  18. Log-Message 'Start'
  19.  
  20. foreach ($i in $location) {
  21.     $url = "$baseUrl$i"
  22.     Log-Message "Trying $url"
  23.     $res = & curl.exe -sS -o NUL -w '%{http_code}' -- $url
  24.     Log-Message "HTTP status code: $res for $url"
  25.  
  26.     if ($res -ne '200' -and $res -ne '401' -and $res -ne '403') {
  27.         $failures += "$i -> $res"
  28.     }
  29. }
  30.  
  31. if ($failures.Count -gt 0) {
  32.     Log-Message "Summary: $($failures.Count) non-200/401/403 status code(s) found"
  33.     foreach ($item in $failures) {
  34.         Log-Message "Failure: $item"
  35.     }
  36. }
  37. else {
  38.     Log-Message 'Summary: all checks returned HTTP 200, 401, or 403'
  39. }
  40.  
  41. Log-Message 'Done'

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.