Powershell: загружайте и анализируйте только новые обновления RSS - PullRequest
0 голосов
/ 30 апреля 2020

Я почти закончил со скриптом RSS, используя Powershell. Все работает и выдает информацию как надо. Теперь мне просто нужно скачать ленту RSS, которая была недавно обновлена. Выполняя некоторые копания, в файле rss есть поле с именем LastBuildDate. Я хотел бы использовать это в качестве переменной для сравнения lastbuilddate с текущим моментом и представлять только последний RSS-канал.

Может ли кто-нибудь помочь мне с тем, как это сделать? Спасибо

 [void][System.Reflection.Assembly]::LoadWithPartialName("System.Web")
 $webclient = new-object System.Net.WebClient
 $url="https://*.rss"
 ## Get the web page into a single string
 $data =[xml]$webclient.downloadstring($url)

if ($data -ne $Null) {
Write-Host -backgroundcolor Yellow -foregroundcolor blue `
$data.rss.channel.Title
Write-Host "Last Updated" $data.rss.channel.LastBuildDate `n
$i=0
do {
 write-Host -foregroundcolor White `
$data.rss.channel.item[$i].Title
 #color code description based on severity
 if ($data.rss.channel.item[$i].Description `
     -Like "*Outage*") {
 $color="Red"
 }
 elseif ($data.rss.channel.item[$i].Description `
  -Like "*Degradation*"){
 $color="Yellow"
 }
 else {
 $color="Green"
}
 Write-Host -foregroundcolor $color `
 $data.rss.channel.item[$i].Description `n
$i++
}
until ($i -gt ($data.rss.channel.item).count)
}
else {
 Write-Host -foregroundcolor Red "Could not get " $url
}

XML Образец:

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Alerts</title>
<link>https://URL</link>
<description>Alerts for the last 7 days, plus Planned Maintenance for the next 5 days.</description>
<lastBuildDate>29 Apr 2020 16:35:46 -0400</lastBuildDate>
<language>en-us</language>
<generator>Alerts 1.0</generator>
<image>
<url>https://URL</url>
<title>Alerts</title>
<link>https://URL</link>
</image>
<atom:link href="https://URL" rel="self" type="application/rss+xml" /><item>
<title>Turnitin Degradation</title>
<link><![CDATA[https://URL></link>
<pubDate>27 Apr 2020 06:26:11 -0400</pubDate>
<guid isPermaLink="false">34e353a7dbd41c5c7fb5266e139619d8</guid>
<description><![CDATA[<p><strong>People and Locations Impacted: </strong><br />All staff at all locations<br /><br /><strong>IT  Service(s) Impacted:</strong><br />TurnItIn at the organization<br  /><br /><strong>Date and Time:</strong><br />TurnItIn are reporting that they began experiencing issues at approximately 10:04 PM on 4/26/2020.<br />TurnItIn have advised that all systems and features should be operational as of 6:10 am 4/27/2020.<br /><br /><strong>Notes:</strong><br />Services affected include:d Paper Submissions, Report Processing Time, and Feedback Studio Access<br /><br /><strong>Technical Information:</strong><br />This alert will be updated as new information becomes available. IT users can view additional details in ServiceNow.<br /><br /><strong>Public Contact for this Alert:</strong><br />IT Service Desk<br />servicedesk@*.com<br />888-888-HELP</p>]]></description>
 </item>
...