Hello,
I’m trying to create a script that gets weather information from a website. When I run this, it’s giving me this error. I’m not sure what I’m doing wrong.
This is the video I’m referencing https://www.youtube.com/watch?v=VmHDiXQTs1s
if I add “/” in $check so that it is
$check = Invoke-WebRequest (“AWC - ADDS” + $urlForms.Action) -WebSession $weather -Method Post -Body $urlForms.Fieldsit gives no error messages, but it doesn’t give me any weather information.
Invoke-WebRequest : The remote server returned an error: (404) Not Found.
At U:\PowerShell\CheckWeather.ps1:12 char:14
- … $check = Invoke-WebRequest (“AWC - ADDS” + $u …
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~- CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
- FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
This is my script so far.
$url = Invoke-WebRequest "http://aviationweather.gov/adds" -SessionVariable weather
if($url.StatusCode -eq 200) {
Write-Host "Connected to Aviation Weather Center" -ForegroundColor Green
$zipcode = Read-Host "Enter the zip code or city"
$urlForms = $URL.Forms[0]
$urlForms.fields["autocomplete"] = $zipcode
$check = Invoke-WebRequest ("http://aviationweather.gov/adds" + $urlForms.Action) -WebSession $weather -Method Post -Body $urlForms.Fields
}
else {
Write-Host "Could not connect to Aviation Weather Center" -ForegroundColor Red
}