ExportedFunctions/ConvertTo-QRCode.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<#
.SYNOPSIS
    Converts input to a QRCode object.

.DESCRIPTION
    Uses the ZXing.Net library to convert input to a QRCode object.

.PARAMETER InputObject
    The data to encode into a QRCode

.PARAMETER ErrorCorrection
    The ammount of redundant data to include in the QRCode for error correction.

.EXAMPLE
    ConvertTo-QRCode -InputObject "http://www.example.com" | Format-QRCode

    This converts the URL to a QRCode an then uses the Format-QRCode function to output the code on the screen.
#>

function ConvertTo-QRCode {
    param(
        [Parameter(ValueFromPipeline=$true,Mandatory=$true)]
        $InputObject,
        
        [ValidateSet("H","L","M","Q")]
        [Parameter(Mandatory=$false)]
        $ErrorCorrection = "M"
    )
    process {
        [ZXing.QrCode.Internal.Encoder]::Encode($InputObject, [ZXing.QrCode.Internal.ErrorCorrectionLevel]::$ErrorCorrection)
    }
}
Export-ModuleMember -Function ConvertTo-QrCode