New-QRCodeTwitter.ps1

function New-QRCodeTwitter
{
    <#
            .SYNOPSIS
            Creates a QR code graphic containing a twitter profile
 
            .DESCRIPTION
            Creates a QR code graphic in png format that - when scanned by a smart device - opens the twitter profile.
 
            .PARAMETER ProfileName
            The twitter profile name
            .PARAMETER Show
            Opens the generated QR code in associated program
 
            .PARAMETER OutPath
            Path to generated png file. When omitted, a temporary file name is used.
 
            .EXAMPLE
            New-QRCodeTwitter -ProfileName tobiaspsp -Width 200 -Show -OutPath "$home\Desktop\qr.png"
            Creates a QR code png graphics on your desktop, and opens it with the associated program
 
            .NOTES
            Compatible with all PowerShell versions including PowerShell 6/Core
            Uses binaries from https://github.com/codebude/QRCoder/wiki
 
            .LINK
            https://github.com/codebude/QRCoder/wiki
    #>


    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory)]
        [string]
        $ProfileName,
        
        [ValidateRange(10,2000)]
        [int]
        $Width = 100,

        [Switch]
        $Show,

        [string]
        $OutPath = "$env:temp\qrcode.png"
    )

    
    $payload = "http://www.twitter.com/$profileName"

    Add-Type -Path $PSScriptRoot\binaries\QRCoder.dll
 
    $generator = New-Object -TypeName QRCoder.QRCodeGenerator
    $data = $generator.CreateQrCode($payload, 'Q')
    $code = new-object -TypeName QRCoder.PngByteQRCode -ArgumentList ($data)
    $byteArray = $code.GetGraphic($Width)
    [System.IO.File]::WriteAllBytes($outPath, $byteArray)

    if ($Show) { Invoke-Item -Path $outPath }
}