Last active
August 3, 2025 13:33
-
-
Save meredoth/a95398fdd5561d151bd5fd84d6ea2740 to your computer and use it in GitHub Desktop.
A PowerShell script that takes a Discourse topic URL and prints all posts containing external links. This is useful for identifying spam posts that hide links in subtle places, such as within commas or periods. If a post seems suspicious, run this script with the Discourse topic URL as a parameter to display all external links found in the posts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| .SYNOPSIS | |
| Takes a discourse topic url and prints all posts that contain external links. Useful for identifying spam posts that hide links in subtle places, such as within commas or periods. | |
| .DESCRIPTION | |
| The Check-Discourse-Topic-Links script takes a URL and uses the Invoke-RestMethod to check each post for the presence of a link_counts field. If the field exists, the script checks whether its internal property is set to false. If so, it prints the post number, the username of the post's author, and the external link. | |
| .PARAMETER discourseTopic | |
| The discourse topic url to check. Note: the url must begin with http:// or https:// | |
| .EXAMPLE | |
| .\Check-Discourse-Topic-Links.ps1 https://discussions.unity.com/t/is-it-a-good-idea-to-put-my-game-on-itch-io-first/1657629 | |
| #> | |
| [CmdletBinding()] | |
| param | |
| ( | |
| [Parameter(Mandatory=$True)] | |
| [string]$discourseTopic | |
| ) | |
| $pageNumber = 0 | |
| Write-Host "`n" | |
| while($True) | |
| { | |
| $pageNumber++ | |
| $currentPage = $discourseTopic + ".json?page=" + $pageNumber | |
| try | |
| { | |
| Write-Verbose "Getting all posts from $discourseTopic page $pageNumber" | |
| $pageData = (Invoke-RestMethod -UserAgent ([Microsoft.PowerShell.Commands.PSUserAgent]::Chrome) -Method GET -Uri $currentPage) | |
| } | |
| catch | |
| { | |
| exit | |
| } | |
| $allPosts = $pageData.post_stream.posts | |
| foreach($post in $allPosts) | |
| { | |
| Write-Verbose "Checking post: $($post.post_number) by $($post.username) `n" | |
| if($post.link_counts) | |
| { | |
| Write-Verbose "Links found in post number $($post.post_number) `n" | |
| foreach($link in $post.link_counts) | |
| { | |
| Write-Verbose "Link: $link `n" | |
| if($link.internal -eq $False) | |
| { | |
| Write-Output "External link found in post number: $($post.post_number) by $($post.username)" | |
| Write-Output "$($link.url) `n" | |
| Write-Verbose "Post body: $($post.cooked) `n" | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment