Repository navigation
Get XKCD
Gets the details of the comics @ https://xkcd.com/. Optionally can download the comic images.
Get-XKCD [-Download] [-Offline] [-Open] [-Show] [-Explain] [-Path <String>] [-HighQuality]
[-StatePath <String>] [-CachePath <String>] [[-Number] <Int32[]>] [-Force] [-NoStateUpdate] [-Raw]
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
Get-XKCD [-Random] [-Minimum <Int32>] [-Maximum <Int32>] [-Download] [-Offline] [-Open] [-Show] [-Explain]
[-Path <String>] [-HighQuality] [-StatePath <String>] [-CachePath <String>] [-Force] [-NoStateUpdate] [-Raw]
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
Get-XKCD [-Newest <Int32>] [-Download] [-Offline] [-Open] [-Show] [-Explain] [-Path <String>] [-HighQuality]
[-StatePath <String>] [-CachePath <String>] [-Force] [-NoStateUpdate] [-Raw]
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
Get-XKCD [-Next] [-Download] [-Offline] [-Open] [-Show] [-Explain] [-Path <String>] [-HighQuality]
[-StatePath <String>] [-CachePath <String>] [-Force] [-NoStateUpdate] [-Raw]
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
Get-XKCD [-Previous] [-Download] [-Offline] [-Open] [-Show] [-Explain] [-Path <String>] [-HighQuality]
[-StatePath <String>] [-CachePath <String>] [-Force] [-NoStateUpdate] [-Raw]
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
The Get-XKCD cmdlet gets the details of one or more comics from the XKCD API: https://xkcd.com/json.html. This includes title, number, image URL, alt text, day, month, year, news, safe_title and transcript. Each returned comic also has a 'date' property (a [datetime] combining day/month/year, so results can be sorted or filtered by date), and 'html_img'/'html' properties, computed from those properties, for embedding the comic in HTML output -- 'html_img' is just the <img> tag, and 'html' wraps that same tag in a link to the comic's page on xkcd.com.
By default, Get-XKCD returns the details of the latest available comic. When you use the -Number parameter (aliased as -Num) you can specify one or more specific comics to return.
Whenever Get-XKCD returns one or more comics -- including the default latest comic, -Number, -Random, and -Newest, not just -Next/-Previous -- it updates a local state file with two records: the highest-numbered comic you've ever viewed, used by Test-XKCD to report how many new comics have been published since you last checked; and the comic most recently displayed or retrieved in either direction, used by -Next and -Previous so you can page back and forth through comics sequentially -- calling -Next or -Previous repeatedly moves one comic further each time. If a call returns multiple comics (e.g. -Newest 5), the state reflects the last one returned. -Next returns nothing once you've reached the latest comic, and -Previous returns nothing once you've reached comic #1. -Show updates the state itself via Show-XKCD, since it doesn't return a comic object here; -Explain does not update the state.
Use -Offline to return comic data from the local cache (created/refreshed by Update-XKCDCache) instead of querying the xkcd API -- this also governs where -Random/-Newest/-Next/-Previous consider the "latest" comic to be. Combined with -Show, the comic's image is rendered from a copy previously saved with -Download rather than downloaded fresh; if that copy doesn't exist yet, a warning is shown asking you to use -Download first. Defaults to the value saved with Set-XKCDDefault -Offline, if any.
Get-XKCD
This command gets the details of the latest XKCD comic from the API such as the title, number, image URL and alt text.
Get-XKCD 42
This command returns the details of the 42nd XKCD comic.
Get-XKCD -Random
This command returns the details of a random XKCD comic from the set of all available comics.
Get-XKCD -Random -Minimum 100 -Maximum 150
This command returns a random comic that is numbered between 100 and 150.
Get-XKCD -Newest 5
This command returns the details of the latest 5 comics.
Get-XKCD -Next
This command returns the details of the comic after the one you most recently displayed or retrieved with -Next/-Previous, as recorded in the state file. Calling -Next repeatedly steps forward further each time. Returns nothing if you're already at the latest comic.
Get-XKCD -Previous
This command returns the details of the comic before the one you most recently displayed or retrieved with -Next/-Previous, as recorded in the state file. Calling -Previous repeatedly steps back further each time. Returns nothing if you're already at comic #1.
Get-XKCD -Download
This command returns the details of the latest comic and downloads the comic image to the current working directory.
Get-XKCD (1..10) -Download -Path C:\Comics
This command returns the details of comic numbers 1 to 10 and downloads each comics image to C:\Comics.
Get-XKCD -Download -HighQuality
This command returns the details of the latest comic and downloads the higher resolution (_2x) version of the image, if one is available. Older comics that do not have a higher resolution version are downloaded at the standard quality instead.
Get-XKCD -Show
This command displays the title, image, and alt text of the latest comic directly in the console (image display requires your terminal to support the Sixel, Kitty, or iTerm2 inline image protocol). Unlike other parameter combinations, -Show does not return the comic object.
Get-XKCD -Explain
This command displays the explanation of the latest comic directly in the console, via Show-XKCDExplanation. Unlike other parameter combinations, -Explain does not return the comic object.
Get-XKCD -Raw
This command returns the latest comic exactly as received from the xkcd API, without the 'date', 'html_img' or 'html' properties Get-XKCD normally adds.
Get-XKCD -Offline
This command returns the details of the latest cached comic from the local cache (created/refreshed by Update-XKCDCache), without querying the xkcd API. Requires a local cache to already exist.
Get-XKCD -Show -Offline
This command displays the latest cached comic's title and alt text in the console, rendering its image from a copy previously saved with -Download, instead of fetching anything from the xkcd API. If the image hasn't been downloaded yet, a warning is shown asking you to use -Download first.
1..10 | % { Get-XKCD -Random | select num,img } | FT -AutoSize
This command returns the details of 10 random comics from the set of all comics and displays the number and image URL of those comics as an autosized table.
(Get-XKCD).html
This command returns an HTML <img> tag (linking to the comic's page on xkcd.com) for the latest comic, suitable for embedding in an HTML page or email.
(Get-XKCD).html_img
This command returns a plain HTML <img> tag (with no surrounding link) for the latest comic.
Gets a random comic.
Type: SwitchParameter
Parameter Sets: Random
Aliases:
Required: True
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseUse with -Random to define a lower bound range within which to return a comic.
Type: Int32
Parameter Sets: Random
Aliases:
Required: False
Position: Named
Default value: 1
Accept pipeline input: False
Accept wildcard characters: FalseUse with -Random to define an upper bound range within which to return a comic. -Maximum is the latest comic number by default.
Type: Int32
Parameter Sets: Random
Aliases:
Required: False
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: FalseGets the specified number of the most recent comics.
Type: Int32
Parameter Sets: Newest
Aliases:
Required: False
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: FalseGets the comic after the one most recently displayed or retrieved with -Next/-Previous, as recorded in the state file. Returns nothing if you're already at the latest comic.
Type: SwitchParameter
Parameter Sets: Next
Aliases:
Required: True
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseGets the comic before the one most recently displayed or retrieved with -Next/-Previous, as recorded in the state file. Returns nothing if you're already at comic #1.
Type: SwitchParameter
Parameter Sets: Previous
Aliases:
Required: True
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseDownloads the images of all returned comics to the local computer.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseReturns comic data from the local cache instead of querying the xkcd API, and (with -Show) renders the comic's image from a copy previously saved with -Download instead of downloading it fresh -- warning and skipping the comic's display if that copy doesn't exist yet. Defaults to the value saved with Set-XKCDDefault -Offline, if any.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: (Get-XKCDDefaultValue -Name 'Offline' -Value $false)
Accept pipeline input: False
Accept wildcard characters: FalseOpens the comic/s in your default web browser
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseDisplays the comic's title, image, and alt text in the console instead of returning the comic object. Image display requires your terminal to support the Sixel, Kitty, or iTerm2 inline image graphics protocol.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseDisplays the comic's explanation in the console via Show-XKCDExplanation, instead of returning the comic object.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseUse with -Download to specify a local directory to download to. By default this is the current working directory, unless a default has been saved with Set-XKCDDefault -Path.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: (Get-XKCDDefaultValue -Name 'Path' -Value $PWD)
Accept pipeline input: False
Accept wildcard characters: FalseUse with -Download to download the higher resolution (_2x) version of the image, where available. Comics that do not have a higher resolution version are downloaded at the standard quality instead. Defaults to the value saved with Set-XKCDDefault -HighQuality, if any.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: (Get-XKCDDefaultValue -Name 'HighQuality' -Value $false)
Accept pipeline input: False
Accept wildcard characters: FalseUse with -Show to specify the file used to track the number of the most recently viewed comic (used by Test-XKCD). By default this is in the user's per-user data directory (~/.xkcd), unless a default has been saved with Set-XKCDDefault -StatePath.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: (Get-XKCDDefaultValue -Name 'StatePath' -Value (Get-XKCDUserDataPath -FileName 'XKCD.state.json' -LegacyDirectory $PSScriptRoot))
Accept pipeline input: False
Accept wildcard characters: FalseUse with -Offline to specify where comic data is cached. By default this is within the module path, unless a default has been saved with Set-XKCDDefault -CachePath.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: (Get-XKCDDefaultValue -Name 'CachePath' -Value (Join-Path $PSScriptRoot 'XKCD.json'))
Accept pipeline input: False
Accept wildcard characters: FalseGets the specified comics. Accepts array input.
Type: Int32[]
Parameter Sets: Specific
Aliases: Num
Required: False
Position: 1
Default value: $Maximum
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: FalseBypass the confirmation check if you try to open more than 9 comics in your browser.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseSkips updating the state file's LastRead/LastViewed records for this call. Used internally by other cmdlets (e.g. Show-XKCDExplanation, Export-XKCDTerminalImage) that fetch comic data as a means to another end, so that fetch doesn't itself count as a comic having been read/viewed.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseReturns the comic object exactly as received from the xkcd API, without the 'date', 'html_img' or 'html' properties Get-XKCD normally adds, and without the 'XKCD.Comic' type name that drives its table/list formatting.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: FalseShows what would happen if the cmdlet runs. The cmdlet is not run.
Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalsePrompts you for confirmation before running the cmdlet.
Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False{{Fill ProgressAction Description}}
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseThis cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).