Repository navigation
Home
This PowerShell module provides cmdlets for querying, downloading and displaying the excellent webcomics published by Randall Munroe at https://xkcd.com. Randall provides an open API for his comics, which this module uses to query the metadata for each comic. The results of the API are also cached locally in the module, so that once it has been loaded once it does not require internet access to query again.
When this module was initially written back in 2017, it just wrapped the API and added some controls that allowed a user to return a specific or random comic, or a random comic within a specified range via a cmdlet called Get-XKCD.
Get-XKCDNum : 3316
Title : Siege Engine
Date : 2026-10-26
Alt : They initially thought the containment structure alone would be sufficient, but for
good measure they decided to include the Elephant's Foot inside.
Img : https://imgs.xkcd.com/comics/siege_engine.png
My motivation at the time was just as a way to demonstrate how to use parameter sets in PowerShell, which allow a PowerShell function to be executed in different ways by providing different combinations of inputs that work with each other. For example, -Min and -Max only work when provided with -Random.
In 2018 I made some fixes to allow the module to work properly cross-platform, due to the release of PowerShell Core (now PowerShell 7).
In 2019, I added a Find-XKCD cmdlet, which uses the cache of the comic APIs (and refreshes it when out of date) to allow you to find a specific comic based on matching text in its title.
Find-XKCD -Query RomanceNum Date Title Img
--- ---- ----- ---
919 2011-07-01 Tween Bromance https://imgs.xkcd.com/comic…
I also added an -Open switch to Get-XKCD so that you could query for a specific comic and trigger its URL to open in your default web browser. I added a safety net to this, so that if you tried to open more than 10 comics at once it prompted you, unless you use -Force, so you didn't inadvertently DoS yourself.
After this, the module went untouched for a number of years, but in 2026 someone raised an issue advising me that there are now high quality versions of each of the comic images (you just add 2x in the URL). The API doesn't expose these URLs directly, but they can be inferred. I updated Get-XKCD so that if you provide a -HighQuality switch with -Download you'd get the High quality image instead of the standard one, where it exists.
This reignited my interest in the module, and I'd seen elsewhere that there were now ways to render images directly in modern terminals, so with the aid of Claude, I added a Show-XKCD cmdlet that you can now use to render a comic directly. On Windows, this uses Sixel to generate the image (which takes a short time to compute), but on MacOS or Linux if you're using iTerm2 or Kitty (or a terminal that supports their graphics protocols) the image is rendered more quickly. I also added -Show to Get-XKCD so that the original entry cmdlet of the module could also be used to trigger displaying the comic in the terminal.
After this I kept having other ideas for the module, and with AI it was then very easy to implement them, and because I had earlier implemented a build pipeline (including Pester unit tests), it added a safety rail in which to AI develop features, ensure they worked cross platform and that they did not impact any earlier functionality.
I added a Get-XKCDCache cmdlet, to allow someone to just query the local API cache directly. With this you can answer interesting questions about all of the comics, such as how many comics were published on Friday 13th:
Get-XKCDCache | Where { $_.Date.DayOfWeek -eq 'Friday' -and $_.Day -eq 13 }Sometimes XKCD comics can be hard to understand (if you're not a mathematician or physicist for example), so there's a website that Explains each XKCD comic shortly after they're published. I added Get-XKCDExplanation and Show-XKCDExplanation as a way to retrieve and display these explanations in the terminal. And I added -Explain to Get-XKCD, to jump to the explanation from Get-XKCD just like you can with -Show. The explanation wiki has different sections (The explanation, a transcript of any text in the comic, a discussion feed of the sites users) so I added switches to allow a user to display these at their choosing. I also ensured that the -Random -Min -Max -Newest <X> parameters from Get-XKCD existed on all other applicable cmdlets.
I added -Next and -Previous switches to Get-XKCD and Show-XKCD, so you a user could paginate through the comics just like they can on the website, and I made it so that it recorded a state file of whichever comic you viewed last, so it would always then pick up from the same place.
I added a Test-XKCD cmdlet, which you can use to validate if a specific comic exists, which is useful as a way to check for new comics. This cmdlet also has an -AddToProfile switch that updates your PowerShell profile with a line of code so that every time you open PowerShell, it does a check for new comics and tells you how many you have not yet seen.
It occurred to me that it might be useful to export the rendered terminal images to a file, particularly for Sixel where they take a few seconds to render. This might help someone who wants a particular XKCD to appear as part of some other script or task, and doesn't want the time delay from rendering it each time, so I added Export-XKCDTerminalImage and Import-XKCDTerminalImage cmdlets to allow someone to do this.
Someone on Bluesky asked if I could add a property to the output of Get-XKCD that includes a comic wrapped in the HMTL tags required to display it. I added this as computed properties so they'd be generated on the fly each time a comic was queried, rather than add something to the API cache that wasn't in the real API. I also added a date property in a similar way, so you have a PowerShell [datetime] object to query, as well as the APIs original day month year properties. I added a PowerShell format file to improve the output of XKCD results in the terminal by default, limiting which properties are displayed and formatting the date.
I made some improvements to Find-XKCD, so that you could do more advanced queries by default with the cmdlet, by adding -Or and -And and -Not parameters as well as -Year, -Month and -Day. It can also now search across the full API result, rather than just the title text. So for example you can now do:
Find-XKCD Spider -Not ManNum Date Title Img
--- ---- ----- ---
8 2006-01-01 Red spiders https://imgs.xkcd.com/comics/r…
43 2006-01-01 Red Spiders 2 https://imgs.xkcd.com/comics/r…
47 2006-01-09 Counter-Red Spiders https://imgs.xkcd.com/comics/c…
126 2006-07-10 Red Spiders Cometh https://imgs.xkcd.com/comics/r…
1747 2016-10-17 Spider Paleontology https://imgs.xkcd.com/comics/s…
I added an -Offline switch to the cmdlets, so that you can have it load from a locally cached version of the comic rather than from the website. So if you've downloaded a set of comics you refer to frequently, you save on internet calls and can view comics even from a post apocalyptic bunker.
Most recently I added Start-XKCD, a slightly tongue-in-cheek Terminal User Interface (TUI) for XKCD, which is intended to parody the real xkcd.com website, in an ASCII terminal way (although the images are obviously rendered as with the other cmdlets).
To view the PowerShell help output for any of the cmdlets in the module, see the pages in the sidebar to the right, or the table below.
This module provides the following cmdlets:
| Cmdlet | Synopsis |
|---|---|
| Get-XKCD | Gets the details of the comics @ https://xkcd.com/. Optionally can download the comic images. |
| Show-XKCD | Displays a comic's title, image, and alt text in the console. |
| Find-XKCD | Retrieves the details of comics @ https://xkcd.com/ based on whether a specified search string appears in the title text (by default). To search for a specified string in the full text of the comic data, use the -FullSearch switch. |
| Update-XKCDCache | Updates the local cache of the XKCD API. |
| Get-XKCDCache | Returns the details of comics @ https://xkcd.com/ from the local cache. |
| Test-XKCD | Checks whether any new comics have been published since the last time Test-XKCD was run. |
| Get-XKCDExplanation | Gets the explanation of a comic from the explain xkcd wiki: https://www.explainxkcd.com/. |
| Show-XKCDExplanation | Displays a comic's title, image, and explanation in the console. |
| Set-XKCDDefault | Sets default preferences used automatically by other cmdlets in this module, such as whether to use high quality images by default. |
| Get-XKCDDefault | Gets the default preferences saved by Set-XKCDDefault. |
| Export-XKCDTerminalImage | Renders a comic using the current terminal's inline image graphics protocol (Sixel, Kitty, or iTerm2) and saves the result to a file, so it can be redisplayed later with Import-XKCDTerminalImage. |
| Import-XKCDTerminalImage | Redisplays a comic's image from a file previously saved with Export-XKCDTerminalImage. |
| Start-XKCD | Opens a full-screen terminal interface for browsing XKCD comics -- a TUI parody of https://xkcd.com/. |
Return details of the latest comic:
Get-XKCDNum : 3316
Title : Siege Engine
Date : 2026-10-26
Alt : They initially thought the containment structure alone would be sufficient, but for good measure they decided to include the
Elephant's Foot inside.
Img : https://imgs.xkcd.com/comics/siege_engine.png
Return details of a specific comic:
You can also provide the number via the pipeline, e.g
1234 | Get-XKCD, and provide multiple values:1,2,3 | Get-XKCD,Get-XKCD -Number 1,2,3, as well as return a Random comic withGet-XKCD -Randomand set a min/max range for the selection viaGet-XKCD -Min 1 -Max 100.
Get-XKCD -Number 2345Num : 2345
Title : Wish on a Shooting Star
Date : 2020-08-12
Alt : Congratulations to whoever wished for revenge on a forest near the Tunguska River, a 1980 Chevy Malibu in Peekskill NY,
Alabama resident Ann Hodges, every building in Chelyabinsk with glass windows, and the non-avian dinosaurs.
Img : https://imgs.xkcd.com/comics/wish_on_a_shooting_star.png
Download a comic:
Downloads to the current path by default, or a path you specify via
-Path.
Get-XKCD -Number 123 -DownloadOpen a comic in your default web browser:
Get-XKCD -Number 123 -OpenRender the latest comic in the terminal:
Show-XKCD
Find comics that match a specified string in the comic title:
Find-XKCD -Query CovidNum Date Title Img
--- ---- ----- ---
2333 2020-07-15 COVID Risk Chart https://imgs.xkcd.com/comic…
2346 2020-08-14 COVID Risk Comfort Zone https://imgs.xkcd.com/comic…
2355 2020-09-04 University COVID Model https://imgs.xkcd.com/comic…
2395 2020-12-07 Covid Precaution Level https://imgs.xkcd.com/comic
Find comics that match two specified strings anywhere in the API results, but exclude another string:
Find-XKCD -Query Spider -Or Super -Not Man -FullSearchNum Date Title Img
--- ---- ----- ---
43 2006-01-01 Red Spiders 2 https://imgs.xkcd.com/comic…
47 2006-01-09 Counter-Red Spiders https://imgs.xkcd.com/comic…
60 2006-02-06 Super Bowl https://imgs.xkcd.com/comic…
107 2006-05-26 Snakes on a Plane! 2 https://imgs.xkcd.com/comic…
...
Open the XKCD Terminal User Interface:
You can also specify
-Numberfor a specified comic, and-Random,-Min,-Max. You could also chainGet-XKCDinto this cmdlet, for exampleGet-XKCD -Random -Min 1000 -Max 2000 | Start-XKCD.
Start-XKCD
Controls:
Gprompts for a comic number to jump straight to.Fdisplays the first comic (#1).Por theleft arrowdisplays the previous comic (does nothing at comic #1).Rdisplays a random comic from the full archive.Nor theright arrowdisplays the next comic (does nothing once you reach the latest comic).Ldisplays the latest comic.QorEscapeexits back to your normal console.
Save a default setting for use by all applicable cmdlets.
Supported preferences:
-HighQualityDefault for -HighQuality on Get-XKCD, Show-XKCD, Start-XKCD, Get-XKCDExplanation, Show-XKCDExplanation and Export-XKCDTerminalImage.-PathDefault download directory for Get-XKCD -Download, and default save directory for Export-XKCDTerminalImage.-FullSearchDefault for -FullSearch on Find-XKCD.-SkipCacheRefreshDefault for -SkipCacheRefresh on Find-XKCD.-CachePathDefault comic data cache location for Update-XKCDCache, Get-XKCDCache and Find-XKCD.-StatePathDefault location of the most-recently-viewed record for Show-XKCD, Start-XKCD, Get-XKCD -Show and Test-XKCD.-ExplanationDefault for -Explanation on Get-XKCDExplanation and Show-XKCDExplanation.-TranscriptDefault for -Transcript on Get-XKCDExplanation and Show-XKCDExplanation.-DiscussionDefault for -Discussion on Get-XKCDExplanation and Show-XKCDExplanation.-FullDefault for -Full on Get-XKCDExplanation and Show-XKCDExplanation.-OfflineDefault for -Offline on Get-XKCD, Show-XKCD, Start-XKCD, Find-XKCD, Export-XKCDTerminalImage and Test-XKCD.-AsPlainTextDefault for -AsPlainText on Get-XKCDExplanation.
For example:
Set-XKCDDefault -HighQuality -Path $Home\.xkcd\imagesHighQuality Path
----------- ----
True C:\Users\wragg\.xkcd\images