PowerShell Function:- WordPress.com retrieve blog data using API

A quick PowerShell Function to retrieve blog post data from my blog site – added to Github as may be useful for others!

Run this function easily by:

Get-Blogs -BlogSiteName "thomasthornton.cloud"
alt text

Output:

If you require further Output data from the used api, you can run

$WPBlogRetrieve = Invoke-RestMethod -uri "https://public-api.wordpress.com/rest/v1/sites/$BlogSiteName/posts/?number=100"
$WPBlogRetrieve.posts

Further info on WordPress.com API

Function Get-Blogs {

  Param(
  [string]$BlogSiteName
  )


$WPBlogRetrieve = Invoke-RestMethod -uri "https://public-api.wordpress.com/rest/v1/sites/$BlogSiteName/posts/?number=100"
$WPBlogRetrieve.posts | Select-Object @{"Name" = "Title";"e"= {$_.Title}},
                             @{"Name" = "URL";"e"= {$_.URL}},
                             @{"Name" = "Date"; "Expression" = {get-date ($_.Date) -Format "dd-MMM-yyyy"}} | ft 
}

#Get-Blogs Example
#Get-Blogs -BlogSiteName "thomasthornton.cloud"

Link to GitHub

1 comment

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 )

Facebook photo

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

Connecting to %s