I wanted a script that would email me the daily links that are posted on a web site for a radio show I listen to. This script will need some rewriting for other sites, but it does what I want it to do.
First, I set two variables. One is the URL for the site that has the links and the other is the class associated with the <div> tag that contains the links I want.
To do this I used the Invoke-Webrequest cmdlet. In this case I was prompted to accept a cookie every time the script ran preventing it from being non-interactive. To get around this I had to add the “-UseBasicParsing” switch. Then I use the Select-String cmdlet to parse out the HTML <div> that contains the links.
Now, just use the Send-MailMessage cmdlet to send the variable that contains the links. Since the content is the remaining HTML from the site I use the “-BodyAsHtml” switch.