# New-Avatar Powershell Module

By
,
Powershell
,
Modules
Published 2022-08-18

Link To Download Search-Dictionary Module
https://www.powershellgallery.com/packages/New-Avatar/1.0.0

Ever wondered what you could like as an avatar
Ever wondered what you could like as an avatar

# Powershell Function 📖

Yep same now old story, I been looking at existing public APIs out there that require no authentication or key to be used. This is so if you do decide to download this module you do not need to sign up for an API key. I then found this website which generates 4 different types of avatars:-

The Avatar API I am using
https://robohash.org/

Again I built this module because when checking the powershell gallery for an avatar I was not getting any results returned back to me (apart from the one I done for Universal Dashboard). So I decided it would be a good idea to make this this into a module, to allow others to be able to create custom awesome looking avatars all from the comfort of your own shell.

Another avatar type you can generate with this module
Another avatar type you can generate with this module

Just in-case you missed the last blog, or you are just reading particular blogs, or this could possile be your first blog let us just quickly go over an API again...Please skip if this if you already read it in the last blog...or previous blog to that, or maybe the one before that.

# API ℹ️

You may or may not know about API aka Application Programming Interface. So here is some brief documentation

API An application programming interface is a way for two or more computer programs to communicate with each other. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how to build or use such a connection or interface is called an API specification. A computer system that meets this standard is said to implement or expose an API. The term API may refer either to the specification or to the implementation. In contrast to a user interface, which connects a computer to a person, an application programming interface connects computers or pieces of software to each other. It is not intended to be used directly by a person other than a computer programmer who is incorporating it into the software. An API is often made up of different parts which act as tools or services that are available to the programmer

So come on Adam what does that mean in cave man talk. Well to a simple person like me it would be like going to a McDonalds drive through with no queue and everything just waiting to be given to you. Still not making sense? Okay to me it is the fastest way you can possible achieve the specific answer you are looking for. So yeah maybe I could have downloaded some software to run this for me, but trust unless the program is using an API then this will give you results quicker than the program could. Or like if I was to do this manually, just the processing power and memory that firefox.exe uses on my laptop, it would be slower going via the web than it would for me to make the API call, the result is instant. I know not everyone out there has a 10 year old crappy x86 laptop to do all this experimenting on, but trust if it runs super fast on my laptop (which it does) it should be lightning fast on your nice x64 solid state drive stupid amount of ram machine. In a nutshell that is why to use an API for the task, and secondly to my knowledge APIs are normally only serving one purpose to keep them super fast. By one purpose I mean an API to find train times...It is not going to tell you what the weather will be like, or the services available on each train, it will just give you train times. I hope this paragraph has maybe made more sense than the official wiki guide above.

# New-Avatar 📓

How about a monster avatar from a name you supply
How about a monster avatar from a name you supply

So as I am generating a new random avatar based on the name supplied using this module. New seemed like the best module of choice to go for.

New vs. Add

Use the New verb to create a new resource. Use the Add to add something to an existing container or resource. For example, Add-Content adds output to an existing file. New vs. Set

Use the New verb to create a new resource. Use the Set verb to modify an existing resource, optionally creating it if it does not exist, such as the Set-Variable cmdlet.

Remember if you are unsure of what verb you can use, or what verb you should use, then please check out the link below for full explanation.

Approved Verb Documentation
https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands?view=powershell-7.2

# Top Tip Add Decent Help 📝

Good news, the heat-wave has finally stopped so no excuses for not writing some decent help the first time round. This is the help synopsis I wrote for this particular module.

NAME
    New-Avatar

SYNOPSIS
    Produces a random avatar for the name supplied, then outputs the picture


SYNTAX
    New-Avatar [-Avatar] <String> [-Name] <String> [-OutFile] <String> [<CommonParameters>]


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


PARAMETERS
    -Avatar <String>
        Uses a validated set of pre-defined selections to select the type of avatar you wish to generate

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -Name <String>
        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"

        Required?                    true
        Position?                    2
        Default value
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -OutFile <String>
        Specify the full directory file name including the file extension for this picture -Outfile
        C:\Users\Me\Desktop\DogRobot.jpg

        Required?                    true
        Position?                    3
        Default value
        Accept pipeline input?       false
        Accept wildcard characters?  false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable, and OutVariable. For more information, see
        about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).

INPUTS

OUTPUTS

    -------------------------- EXAMPLE 1 --------------------------

    PS > New-Avatar -Avatar Kitten -Name "Zelda Bacon" -OutFile C:\Builds\ZeldaKitten.jpg






    -------------------------- EXAMPLE 2 --------------------------

    PS > New-Avatar -Avatar Monster -Name "Aurora Bacon" -OutFile C:\Builds\AuroraMonster.jpg






    -------------------------- EXAMPLE 3 --------------------------

    PS > New-Avatar -Avatar Robot -Name "Adam Bacon" -OutFile C:\Builds\AdamRobot.jpg

When building this module instead of using switches as the parameter sets, I decided on ValidateSet to allow the choice for the parameter to be automatically generated, this to me me more sense then having to using Parameter Set Names to show that you could only supply one type of avatar to be generated. If you know of a better way, then please send me a post-card with your answer on it, or alternatively drop me a tweet, it would be great to hear from you.

# I hope you had fun 👋

Hopefully this module will make you think about what you can do with an API. As always I like to try and keep things interesting, and to try and make something unique and useful as the end module product.

Yep this module is pretty pointless, but apart from the one I did for Universal Dashboard, which you either need that product or Powershell Universal to run, a module to create an avatar did not exist on the Powershell gallery hence I made this mini-project into a module.

Apparently this is what my name generates for a kitten avatar
Apparently this is what my name generates for a kitten avatar