Powershell running function one time

Welcome Forums General PowerShell Q&A Powershell running function one time

Viewing 1 reply thread
  • Author
    Posts
    • #230122
      Participant
      Topics: 2
      Replies: 0
      Points: 25
      Rank: Member

      Hi, I have a small script that goes and check for new rss feed every 1 minute, and the function goes to sleep for another minute. How can I make the function not to keep downloading the same title, unless there is a new topic.

      $webclient = new-object System.Net.WebClient
      $url=”https://something”
      ## Get the web page into a single string
      $data = [xml](invoke-webrequest $url).Content
      $Time = Get-Date -format g
      $LastBuiltDate = ($data.rss.channel.LastBuildDate).split(”)[4]
      $TimeDiff = New-TimeSpan -Start $LastBuiltDate -End $Time
      if($TimeDiff.minutes -lt 1){
      $items = ($data.rss.channel.item | select title,Description,link, @{LABEL=”Published”;EXPRESSION={[datetime]$_.pubdate}}|sort-object Published)
      foreach ($msg in $items){
      $titlen = $msg.title -replace ‘<br ?/?>’,[System.Environment]::NewLine -replace ‘<[^>]+>’
      $Published = $msg.Published
      $commentsPlain = $msg.Description.InnerText -replace ‘<br ?/?>’,[System.Environment]::NewLine -replace ‘<[^>]+>’
      $weblinks = $msg.link.innertext
      }

      }

      • This topic was modified 6 months, 2 weeks ago by peterobles97.
      • This topic was modified 6 months, 2 weeks ago by peterobles97.
      • This topic was modified 6 months, 2 weeks ago by peterobles97.
    • #230383
      Participant
      Topics: 17
      Replies: 1872
      Points: 3,640
      Helping Hand
      Rank: Community Hero

      The RSS feed API would need to have filters that could leveraged (e.g. Date) to only return items that are newer than the last request. If there is not filter functionality, then you would have to download the results and use Compare-Object to determine what doesn’t currently exist in the stored data set.

Viewing 1 reply thread
  • The topic ‘Powershell running function one time’ is closed to new replies.