-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from T0biii/master
Add new Function New-PSOneQRCodeText and some more things
- Loading branch information
Showing
10 changed files
with
457 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
function New-PSOneQRCode | ||
{ | ||
<# | ||
.SYNOPSIS | ||
Creates a QR code graphic | ||
.DESCRIPTION | ||
Creates a QR code graphic in png format that - when scanned by a smart device | ||
.PARAMETER Payload | ||
The Payload for the QR code | ||
.PARAMETER Width | ||
Height and Width of generated graphics (in pixels). Default is 100. | ||
.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-PSOneQRCode -payload $payload -Width $width -Show -OutPath $OutPath | ||
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/TobiasPSP/Modules.QRCodeGenerator | ||
#> | ||
|
||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(Mandatory)] | ||
[string] | ||
$payload, | ||
|
||
[Parameter(Mandatory)] | ||
[bool] | ||
$Show, | ||
|
||
[ValidateRange(10,2000)] | ||
[int] | ||
$Width = 100, | ||
|
||
[string] | ||
$OutPath = "$env:temp\qrcode.png" | ||
) | ||
|
||
|
||
$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 } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
function New-PSOneQRCodeGeolocation | ||
{ | ||
<# | ||
.SYNOPSIS | ||
Creates a QR code graphic containing a geo location | ||
.DESCRIPTION | ||
Creates a QR code graphic in png format that - when scanned by a smart device - opens the geo location in a browser. | ||
.PARAMETER Latitude | ||
The location latitude | ||
.PARAMETER Longitude | ||
The location longitude | ||
.PARAMETER Width | ||
Height and Width of generated graphics (in pixels). Default is 100. | ||
.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-PSOneQRCodeGeoLocation -Latitude 21.12 -Longitude 22.87 -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/TobiasPSP/Modules.QRCodeGenerator | ||
#> | ||
|
||
[CmdletBinding(DefaultParameterSetName="Address")] | ||
param | ||
( | ||
[Parameter(Mandatory,ParameterSetName='Location')] | ||
[double] | ||
$Latitude, | ||
|
||
[Parameter(Mandatory,ParameterSetName='Location')] | ||
[double] | ||
$Longitude, | ||
|
||
[Parameter(Mandatory,ParameterSetName='Address')] | ||
[string] | ||
$Address, | ||
|
||
[ValidateRange(10,2000)] | ||
[int] | ||
$Width = 100, | ||
|
||
[Switch] | ||
$Show, | ||
|
||
[string] | ||
$OutPath = "$env:temp\qrcode.png" | ||
) | ||
|
||
if ($PSCmdlet.ParameterSetName -eq "Address") | ||
{ | ||
$AddressEncoded = [System.Net.WebUtility]::UrlEncode($Address) | ||
|
||
$null = Invoke-RestMethod -SessionVariable session -Uri "https://geocode.xyz" | ||
$data = Invoke-RestMethod -WebSession $session -Uri "https://geocode.xyz/${AddressEncoded}?json=1" | ||
if ($null -eq $data.error) | ||
{ | ||
throw "Address not found. $($data.Error.Description)" | ||
} | ||
$Latitude =$data.latt | ||
$Longitude = $data.longt | ||
} | ||
|
||
$payload = @" | ||
geo:$Latitude,$Longitude | ||
"@ | ||
|
||
New-PSOneQRCode -payload $payload -Show $Show -Width $Width -OutPath $OutPath | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
function New-PSOneQRCodeText | ||
{ | ||
<# | ||
.SYNOPSIS | ||
Creates a QR code graphic containing for a Text | ||
.DESCRIPTION | ||
Creates a QR code graphic in png format that - when scanned by a smart device - shows a text. | ||
.PARAMETER Text | ||
The Text to show | ||
.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-PSOneQRCodeText -Text 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/TobiasPSP/Modules.QRCodeGenerator | ||
#> | ||
|
||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(Mandatory)] | ||
[string] | ||
$Text, | ||
|
||
[ValidateRange(10,2000)] | ||
[int] | ||
$Width = 100, | ||
|
||
[Switch] | ||
$Show, | ||
|
||
[string] | ||
$OutPath = "$env:temp\qrcode.png" | ||
) | ||
|
||
|
||
$payload = "$Text" | ||
|
||
New-PSOneQRCode -payload $payload -Show $Show -Width $Width -OutPath $OutPath | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
function New-PSOneQRCodeTwitter | ||
{ | ||
<# | ||
.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-PSOneQRCodeTwitter -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/TobiasPSP/Modules.QRCodeGenerator | ||
#> | ||
|
||
[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" | ||
|
||
Write-Verbose "$ProfileName $Width $Show $OutPath $payload" | ||
|
||
New-PSOneQRCode -payload $payload -Show $Show -Width $Width -OutPath $OutPath | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
function New-PSOneQRCodeVCard | ||
{ | ||
<# | ||
.SYNOPSIS | ||
Creates a QR code graphic containing person data | ||
.DESCRIPTION | ||
Creates a QR code graphic in png format that - when scanned by a smart device - adds a contact to the address book. | ||
.PARAMETER FirstName | ||
Person first name | ||
.PARAMETER LastName | ||
Person last name | ||
.PARAMETER Company | ||
Company name | ||
.PARAMETER Email | ||
email address | ||
.PARAMETER Width | ||
Height and Width of generated graphics (in pixels). Default is 100. | ||
.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-PSOneQRCodeVCard -FirstName Tom -LastName Sawyer -Company "Huckle Inc." -Email [email protected] -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/TobiasPSP/Modules.QRCodeGenerator | ||
#> | ||
|
||
|
||
param | ||
( | ||
[Parameter(Mandatory)] | ||
[string] | ||
$FirstName, | ||
|
||
[Parameter(Mandatory)] | ||
[string] | ||
$LastName, | ||
|
||
[Parameter(Mandatory)] | ||
[string] | ||
$Company, | ||
|
||
[Parameter(Mandatory)] | ||
[AllowEmptyString()] | ||
[string] | ||
$Email, | ||
|
||
[ValidateRange(10,2000)] | ||
[int] | ||
$Width = 100, | ||
|
||
[Switch] | ||
$Show, | ||
|
||
[string] | ||
$OutPath = "$env:temp\qrcode.png" | ||
) | ||
|
||
$Name = "$FirstName $LastName" | ||
|
||
$payload = @" | ||
BEGIN:VCARD | ||
VERSION:3.0 | ||
KIND:individual | ||
N:$LastName;$FirstName | ||
FN:$Name | ||
ORG:$Company | ||
EMAIL;TYPE=INTERNET:$Email | ||
END:VCARD | ||
"@ | ||
|
||
New-PSOneQRCode -payload $payload -Show $Show -Width $Width -OutPath $OutPath | ||
} |
Oops, something went wrong.