#This removes the old temperature weather .txt
Remove-Item "C:\Users\weyou_000\Documents\EZ-Builder\My Projects\PowerShell\CurrentTemperatureMonroe.txt" -ErrorAction SilentlyContinue
#This pulls the local Weather based on zipcode. This only works for the United States, other countries might have different webservices.
#My zip code is 45050, you should need to update the zip code to reflect yours
$uri = "http://wsf.cdyne.com/WeatherWS/Weather.asmx"
$WeatherForecast = New-WebServiceProxy -uri $uri -UseDefaultCredential -namespace "WeatherForecast"
#$WeatherForecast.GetCityWeatherByZIP(45050).details #This line is used if you want to see all avaliable items from this web service
$Condition = $WeatherForecast.GetCityWeatherByZIP(45050).Description
$CurrentTempature = $WeatherForecast.GetCityWeatherByZIP(45050).Temperature
#This writes the temperature and condition of the local weather to a text file
Write-Output $CurrentTempature $Condition | Out-File -FilePath "C:\Users\weyou_000\Documents\EZ-Builder\My Projects\PowerShell\CurrentTemperatureMonroe.txt"
This script deletes the .txt file where current weather data is written (if the file is there), then is makes a web service call to the website and pulls the data. Variables within the script are assigned for temperature and condition and these variables are written to the text file.
You will need to change the location path of the txt file to reflect the file local and name you want to use. You'll also need to change the "45050" zip code to reflect your own.
2. Next you'll need to make a batch file. A batch file is an old school PC script method to automate file functions. In the case, we are using a batch file to run the PowerShell script.
Enter this in the Batch file:
powershell -ExecutionPolicy RemoteSigned -File "C:\Users\weyou_000\Documents\EZ-Builder\My Projects\PowerShell\CurrentTempMonroe.ps1"
Again, change the path and file name to reflect your own. Make sure your batch file ends with .bat. You can create a batch file by opening notepad, and saving the file as, all files and end the file name with .bat.
3. Test your batch file. If you double click on it, it should run and you should see a new .txt file created from the path/file name you defined in the PowerShell script. If text files should have two lines, one for the temperature and one for the weather condition. If you don't have this text file or data in the file, re-check the previous steps.
4. Create a script in EZ-Builder to run the batch file, pause, then read the text file with the temperature data in it.
Enter this in EZ-Builder script:
#This will return the local Monroe,OH temperature and weather condition
#This script calls a batch file and the batch file calls a powershell script
#You must have the batch file and the powershell file configured to use this
$filename = "C:\Users\weyou_000\Documents\EZ-Builder\My Projects\PowerShell\CurrentTemperatureMonroe.txt"
if (FileExists($filename) = false)
print("File does not exist")
$MonroeCurrentTemperature = FileReadLine($filename)
$MonroeCurrentCondition = FileReadLine($filename)
print("Monroe Current Temp: " + $MonroeCurrentTemperature)
Say("Current Monroe Ohio Temperature is " + $MonroeCurrentTemperature)
print("Monroe Current Condition: " + $MonroeCurrentCondition)
Say("and weather condition is " + $MonroeCurrentCondition)
This is my script. You'll need to change the paths of the text file and batch job and you should rename the variables to reflect the name of your local city in the US.
You can repeat this method to pull weather data for multiple US cities.