New-Avatar.psm1
<#
.Synopsis Produces a random avatar for the name supplied, then outputs the picture .DESCRIPTION This is just a fun module, it will not boost your career path using this, but it is cool, so I thought I would make it into a module. This uses the robohash.org API site which will allow you to generate either a robot, or a monster, or a robot disembodied head or finally a kitten. Based on the name you supply .PARAMETER Avatar Uses a validated set of pre-defined selections to select the type of avatar you wish to generate .PARAMETER Name Allows you to supply a name for your avatar type you have selected, like if I was to use the name of my dog it would be -Name "Barney Bacon" .PARAMETER Outfile Specify the full directory file name including the file extension for this picture -Outfile C:\Users\Me\Desktop\DogRobot.jpg .EXAMPLE New-Avatar -Avatar Kitten -Name "Zelda Bacon" -OutFile C:\Builds\ZeldaKitten.jpg .EXAMPLE New-Avatar -Avatar Monster -Name "Aurora Bacon" -OutFile C:\Builds\AuroraMonster.jpg .EXAMPLE New-Avatar -Avatar Robot -Name "Adam Bacon" -OutFile C:\Builds\AdamRobot.jpg #> function New-Avatar { [CmdletBinding(DefaultParameterSetName = 'All')] Param ( [Parameter(Mandatory = $true, HelpMessage = 'Select from one of the pre-defined avatar types this API can produce', Position = 0)] [ValidateSet('Robot', 'Monster', 'RobotHead', 'Kitten')] [string]$Avatar, [Parameter(Mandatory = $true, HelpMessage = 'Enter your name or some other text to see what type of avatar it generates for the given words', Position = 1)] [string]$Name, [Parameter(Mandatory = $true, HelpMessage = 'Enter the full path including jpg extension to where you want the picture saved', Position = 2)] [string]$OutFile ) Begin { Add-Type -AssemblyName System.Web Switch ($Avatar) { 'Robot' { $URL = "" } 'Monster' { $URL = "?set=set2" } 'RobotHead' { $URL = "?set=set3" } 'Kitten' { $URL = "?set=set4" } } $encodedName = [System.Web.HttpUtility]::UrlEncode($Name) } Process { try { Invoke-WebRequest -Uri "https://robohash.org/$encodedName$URL" -OutFile $OutFile -ErrorAction Stop } catch { Write-Warning -Message "Something went wrong $($_)" } } End { Write-Host -ForegroundColor Green "Script has now finished image output to $OutFile" } } |