Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Submit Latest WP Blog Post to MVP Community Contributions
# Install the Microsoft MVP PowerShell Module
# Install-Module -name MVP
Import-Module -Name MVP
# my Subscription Key obtained from https://mvpapi.portal.azure-api.net/
$subkey = '12345669b3c459bb2c11da79567890'
# AuthN to MVP API
Set-MVPConfiguration -SubscriptionKey $subkey
# Get the last Blog Post
$wordpressBlogURL = 'https://public-api.wordpress.com/rest/v1/sites/<yourwordpressURL>/posts/?number=1'
$BlogPostData = Invoke-RestMethod -uri $wordpressBlogURL
# Static because it is obviously a Blog Post
$contributionType = "Blog Site Posts"
# Static as that is my MVP Category
$contributionTechnology = "Identity and Access"
# URL
$contributionURL = $BlogPostData.posts.URL
# Title
$contributionTitle = $BlogPostData.posts.title
# Description
$descriptionHTML = $BlogPostData.posts.excerpt
# Remove HTML Formatting
$contributionDescription = $descriptionHTML -replace '<[^>]+>',''
# Translate Date Format
$date = $BlogPostData.posts.date
$arrDate = $date.Split("T")
$contributionDate = $arrDate[0].Replace("-","/")
# Submit latest Blog Post to MVP Community Contributions Profile
try {
write-host "Submitting your Blog Post titled $($contributionTitle) you wrote on $($contributionDate) to $($contributionTechnology)"
New-MVPContribution -StartDate $contributionDate `
-ContributionTechnology $contributionTechnology `
-ContributionType $contributionType `
-Title $contributionTitle `
-Description $contributionDescription `
-ReferenceUrl $contributionURL `
-Visibility EveryOne } catch {
write-host "Well that was unexpected. Check your last post for anomolies."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment