Writing a script
How do we go about writing a script? Pretty much every script I write from scratch starts with writing down the steps and cmdlets I need to complete a task. Once I can complete the task with only the information in the list, and all the cmdlets work, I know I am ready. Let’s start our script with a working command. As an example, consider the following cmdlet:
Invoke-RestMethod -Uri 'https://api.weatherapi.com/v1/current.json?q=London&aqi=no' -Method GET -Headers @{"key" = "fp3eofkf3-0ef-2kdwpoepwoe03eper30r"}| ConvertTo-Html | Out-File "c:\temp\poshbook\ch8\WeatherData.html"
This cmdlet gets some weather data for my location from the API service from the Weather API, using a personal key, and writes it to an HTML file for display. Obviously, I’ve not put my real personal key in the preceding cmdlet, so it will fail with an API key error if we run that exact code. Let’s consider how we might turn...