Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ConnorGriffin/0eea749f219c61decfd417eace0d8d33 to your computer and use it in GitHub Desktop.
Save ConnorGriffin/0eea749f219c61decfd417eace0d8d33 to your computer and use it in GitHub Desktop.
Outputs a table of any comments that mention a KB number on the reddit.com/r/sysadmin monthly Patch Tuesday megathread
# Get a list of posts from reddit.com/r/sysadmin front page
$posts = Invoke-RestMethod 'https://www.reddit.com/r/sysadmin/.json'
# Get the URL for the patch tuesday megathread
$megathread = $posts.data.children.data.Where{$_.title -like '*Patch Tuesday Megathread*'}
$megathreadUrl = $megathread.Url
# Get the comments of the megathread
$comments = Invoke-RestMethod "$megathreadUrl.json"
# Iterate through the comments, match any KB#######. Case insensitive, there can be any single character between KB and the numbers.
$commentTable = $comments.data.children.data.ForEach{
$match = ([regex]'(?i)kb\d{7}|(?i)kb.\d{7}').Matches($_.body);
if ($match.Value) {
# Return a custom object with the data we want to see
[PSCustomObject] @{
Ups = $_.ups
KB = $match.Value -join ', '
Body = $_.body
}
}
}
# Output the data
$commentTable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment