Skip to the content.

PS: Generating QRCode Images

ZXing is a popular library to work with 1D/2D barcodes, which includes QR codes. It has two useful implementations - a barcode scanner android app, and a web app. The web app allows you to create custom QR codes for your diverse needs.

In this post, we’ll write a PowerShell cmdlet that generates QRCode images (png) for your text. You can take a look at all templates that the app provides in case you’re looking for something specific (eg. Contact Info).

Taking a look at the querystring that generates the QRCode, I noticed that the querystring itself is customizable - you can specify the text, character-encoding, error-correction scheme (L/M/H/Q), and width/height of the image to be generated.

We’ll simply make a request using this querystring, and download the resulting image, both using Invoke-WebRequest.

function Get-QRCode{
<#
.SYNOPSIS
Generates QRCode (.png) from text.

.EXAMPLE
PS> Get-QRCode -Name "Hello World!"
PS> Get-QRCode "http://crtejaswi.github.io"
PS> qrc "http://crtejaswi.github.io"
#>
    [cmdletBinding()]
    [Alias('qrc')]
    param(
        [Parameter (Position=0,Mandatory=$True)]
        [string]$Name
    )
    $QRCode  = "https://zxing.org/w/chart?cht=qr&chs=256x256&chld=L&choe=UTF-8&chl=$Name"
    Invoke-WebRequest $QRCode -OutFile QRCode.png
}

That’s it! In future updates, we’ll try to customize this cmdlet for specific needs.

Sample QRCode