Count Number of Blog Posts thru RSS Feed

There was a requirement to get the count of Blogposts that have been posted by Bloggers, First question is : If it is at all possible to get that automatically thru Powershell magic ?? Yes it can be done as each blog has RSS feed which is XML formatted.

By using Powershell, parsing XML & thru some loop logic we can easily get these numbers.

Sharing the  script that has been written to achieve this goal, Pls download it from below link.

https://gallery.technet.microsoft.com/scriptcenter/Count-Number-of-Blog-Posts-3176d96f

Lets define some variables first. (Blogcount.ps1 file)

#####Define Variables#########
$firstdayofm = ((Get-Date -day 01).AddMonths(-1)).AddDays(0)  #–> this will defin the first day of last Month
$siteurls = gc .\blogurls.txt  # —> Blog urls for which you want to count posts.

########################

After that we need to  update the blogurls.txt file with the blogger sites, I have used some of the MVP’s blog sites as an example.

Note:- You need to use RSS feed urls inside this blogurls.txt file.

Note:- This script is getting count of blogs posted previous month.

Script will loop thru each blog post, count & present it in CSV format.

Its using Invoke-Webrequest method to download the XML & than Parsing it thru [XML]/Get-content method.

Invoke-WebRequest -Uri $blog -OutFile .\XML\$blgxml
[xml]$XMLcontent = gc .\XML\$blgxml

Lets run the script from powershell prompt from the script directory, It will stream the xml to the XML directory.

It will parse thru each XML file & count items for each blog.

Below output will be received after parsing is completed.

 

Let me know if any enhancement is required…

################################################################################# 
#        Author: Vikas Sukhija     
#        Date: 03/11/2015 
#        Modified: 
#        Reviewer: 
#        Description: Count number of Blog posts 
################################################################################# 
 
#####Define Variables######### 
 
$firstdayofm = ((Get-Date -day 01).AddMonths(-1)).AddDays(0) 
 
$siteurls = gc .\blogurls.txt 
 
$Collection = @() 
 
 
#####Browse thru each blog ##### 
 
foreach($blog in $siteurls) 
 
{ 
 
$blogtitle = $blog 
 
$blgtitle = $blogtitle.Split(".")[0].split("//")[2] 
 
$blgxml = $blgtitle + ".xml" 
 
Invoke-WebRequest -Uri $blog -OutFile .\XML\$blgxml 
 
[xml]$XMLcontent = gc .\XML\$blgxml 
 
$items = $XMLcontent.rss.channel.Item  
$count = 0 
 
$items | foreach-object{ 
 
[datetime]$pitem = $_.pubdate  
 
 
if($pitem -ge $firstdayofm ){ 
 
$pitem 
$firstdaypmonth 
 
$count = $count +1 } 
 
} 
 
$coll = “” | select BlogTitle,BlogUrl,count 
$coll.BlogTitle = $blgtitle 
$coll.BlogUrl = $blogtitle 
$coll.count = $count 
 
$Collection +$coll 
 
} 
 
$Collection| export-csv .\BlogCountreport.csv -notypeinfo 
 
##################################################################### 
 
 
 
 
 
 
 

 

Regards

Sukhija Vikas

http://msexchange.me

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s