# Used everytime $User = "username" #$password = Get-Content /home/httpd/sites/datex/cred.txt | ConvertTo-SecureString #$credential = New-Object System.Management.Automation.PsCredential($User,$password) # Magic #[xml]$Weather = Invoke-WebRequest -Credential $credential https://www.vegvesen.no/ws/no/vegvesen/veg/trafikkpublikasjon/vaer/2/GetMeasurementWeatherSiteTable $securepassword = ConvertTo-SecureString "password" -AsPlainText -Force $credentials = New-Object System.Management.Automation.PSCredential($User, $securepassword) [xml]$Weather = Invoke-WebRequest -Uri "https://www.vegvesen.no/ws/no/vegvesen/veg/trafikkpublikasjon/vaer/2/GetMeasuredWeatherData" -Credential $credentials #MET Invoke-webrequest https://api.met.no/weatherapi/textforecast/2.0/?forecast=landoverview -Outfile "response.xml" [xml]$met = New-Object -TypeName xml $met.load("response.xml") $ostlandet_24 = $met.textforecast.time[0].forecasttype.location[0].innertext | Out-File /home/httpd/sites/datex/met24.inc $ostlandet_48 = $met.textforecast.time[1].forecasttype.location[0].innertext | Out-File /home/httpd/sites/datex/met48.inc # MET SLUTT $EndResult = @() $IDs = "206","217","342","1740","73","175","202","142","341","277","210","249","163" Foreach ($place in $IDs) { $Location = $Weather.d2LogicalModel.payloadPublication.siteMeasurements | Where-Object { $_.measurementsitereference.id -eq $place } $LocationAirTemp = ($Location.measuredValue | Where-Object {$_.index -eq "101"}).innertext $LocationHumidity = ($Location.measuredValue | Where-Object {$_.index -eq "201"}).innertext + " %" $LocationDewPoint = ($Location.measuredValue | Where-Object {$_.index -eq "301"}).innertext $LocationRoadTemp = ($Location.measuredValue | Where-Object {$_.index -eq "801"}).innertext [float]$LocationWindSpeed = ($Location.measuredValue | Where-Object {$_.index -eq "901"}).innertext #$LocationWindDir = ($Location.measuredValue | Where-Object {$_.index -eq "901"}).innertext # $LocationVisibility = ($Location.measuredValue | Where-Object {$_.index -eq "1401"}).innertext $LocationPrecipitation = ($Location.measuredValue | Where-Object {$_.index -eq "2501"}).innertext + " mm/h" # $LocationSnowDepth = ($Location.measuredValue | Where-Object {$_.index -eq "3301"}).innertext #if (!$LocationSnowDepth) {$LocationSnowDepth = "-"} if (!$LocationWindSpeed) {[string]$LocationWindSpeed = "-"} else { $LocationWindSpeed = $LocationWindSpeed*5/18 } # Omregning fra km/t til m/s if (!$LocationVisibility) {$LocationVisibility = "-"} $Place = $Place.Replace("206","Lygna").Replace("217","Bekkehallum").Replace("342","Vardalsåsen").Replace("1740","Vingromåsen").Replace("73","Eggemoen").Replace("175","Stryken").Replace("202","Brovoll").Replace("142","Gjelleråsen").Replace("341","Tonsåsen").Replace("277","Andelva").Replace("210","Minnesund").Replace("249","Espa").Replace("163","Vikselv") $Resultname = [PSCustomObject][ordered]@{ Lokasjon = $place Lufttemperatur = $LocationAirTemp Duggpunkt = $LocationDewPoint Veibanetemperatur = $LocationRoadTemp Nedbørintensitet = $LocationPrecipitation Vindhastighet = $LocationWindSpeed # Snødybde = $LocationSnowDepth Luftfuktighet = $LocationHumidity # Siktrekkevidde = $LocationVisibility } $EndResult += $ResultName } $EndResult|Format-Table $fragments = @() $fragments += @' '@ $fragments+= '
Værstatistikk $ostlandet_24
Østlandet 48 timer:$ostlandet_48
" $fragments += @'