QR codes and practical usage

Earlier this year I was lucky to attend the PowerShell Conference Europe [a.k.a. PSConfEU], which is easily the geek highlight of my year.

At the Opening ceremony, organizer and PowerShell GURU Dr. Tobias Weltner showed this gem that amazed me in it’s simplicity

I present you: the QRCodeGenerator

As the name implies, the QRCodeGenerator will generate various QR codes for you to use, all through the magic of PowerShell [and of course the QR generator solution in C# which this module uses].

Of course now we’ll want to play with it, so let’s get the module!

Let’s just assume by now you’ll have at least [Windows] PowerShell 5+, if you don’t, please get it ASAP [or get PowerShell Core instead]!

When searching the PowerShellGallery, you should be presented by the last version

Go ahead and install this module for yourself

or for everyone on your system [be sure to run PowerShell as Administrator]

Ok, so now what?

Let’s see what options we have available

So we can create a new

  • GeoLocation QR Code
  • vCard QR Code
  • Wifi Access QR Code

As expected, each of the provided cmdlets come with properly created help files, examples and all 3 cmdlets have similar input parameters, mainly

  • Width – height and width of the generated code [default is 100]
  • Show – open the generated code in default program
  • OutPath – path to generated png file. If left empty, a temporary file name will be used.

Practical applications

To be honest, the 2 main reasons I liked this are the Wifi Access and vCard codes.
While there might be some use for the GeoLocation one, I would think it’d mainly be in like print media, to display your company’s location information or such.

The New-QRCodeWifiAccess cmdlet can be used at home or at work provide access to your guest wifi network.
Simply generate the code, print and laminate it once and whenever people ask for access, just let them scan the code!

And tada!

As for the New-QRCodevCard cmdlet, it works just the same. In this case I would recommend using it on your business card to allow your contact to easily add you in her/her phone.

 

All in all, I thought this was thing to share, I hope you think so too!

Happy Scripting! 🙂

 

Facebooktwitterredditlinkedinmail

VM Lab – Switch it up

Back again for another part in my VM Lab series.

So far I’ve created the folder structure which we will use to store our ISO files, VHD files [including template VHDs and Unattend.xml files] and VM’s.
In order to manipulate the ReadOnly status of various files [such as the template VHD’s and Unattend.xml files], I’ve provided simple functions which will assist us.

Now we need to make sure that the final piece of the infrastructure is ready: the Hyper-V VM Switches.

Breakdown

As a change of scenery, this time I won’t just dump the code, I’ll try and explain my reasoning behind the code used.
Since the 3 functions [again going for Get- , New- and Remove-] all use the same base structure, I thought it would be nice to explain some method to my madness.
If this isn’t what you’ve come here for, please scroll down to the end of the page and just scoop the final code 🙂

Advanced functions – ValidateSet

There are only select options to choose when creating a VM Switch: External, Internal, Private (and in some versions NAT, but this is not included in my function for now).
In order to limit the user’s choices, I’ve used something called ValidateSet, which gives the end user a predefined list of options to choose from.
Should you manually enter a value which is not defined in the ValidateSet list, access will be denied.

You can find various examples in common Cmdlets, such as

This will give you a predefined set of options to choose from, such as AllSigned, ByPass, Default, RemoteSigned, Restricted, Undefined and Unrestricted.
In my code I limit the user to the default VM Switch types, but I also provide an option to select all 3 types at the same time, All.

This does however require your function to be an advanced function, as defined by

In case you didn’t know yet, adding something as simple as that will provide your function with additional features and functionality, such as being able to use CommonParameters, such as –Verbose or -WhatIf.

For a more in depth view of Standard functions vs Advanced functions, I’d like to refer to these great articles by the following great minds:

Switch statement

Now these are functions about VM Switches, but in my code I also use something called a switch statement.
This allows me to set/change values, based on what value was chosen in my ValidateSet.
There is a great article on Microsoft’s TechNet by The Scripting Guys, which will explain the entire concept better than I can do, so please have a look at that if anything is unclear about the options/usage of this statement.

In my case, this is the logic I used behind it:

At first I have defined all types of VM Switches as a variable

Now through the switch statement, I check which $SwitchType has been selected and I change the accompanying variable to $true

If statement

After the variables are set to either $true or $false using the above mentioned switch statement, I use an if statement which will execute certain code if the value is set to $true.
If the variable is set to $false,  you can have it do something else, of elseif, but for this code it wasn’t important.

By doing this, I can check each VM SwitchType, and if it was set as $true, I would either get, create or remove the VM Switch.
In the above example I also use a try/catch block, but I will try and explain this in a future blog post.

Functions

As per usual, I’ve provided the final code below.

BEWARE

These functions are meant for a test environment.
I’ve borrowed Jeffery Hicks‘ disclaimer, because it simply says it all:

DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED THOROUGHLY IN A LAB ENVIRONMENT.
USE AT YOUR OWN RISK.
IF YOU DO NOT UNDERSTAND WHAT THIS SCRIPT DOES OR HOW IT WORKS, DO NOT USE IT OUTSIDE OF A SECURE, TEST SETTING.

I’ve set the scripts to a max height as to not flood the page, but rest assured, everything’s there.
Please do note that functions might refer to other functions, this is intended as a complete toolset, not just 1 piece.

If you have questions on the techniques used or suggestions on how to improve something, please let me know in the comment section!

Get-LabSwitch

New-LabSwitch

Remove-LabSwitch

 

Facebooktwitterredditlinkedinmail

VM Lab – Read Only status

In this next installment of my  VM Lab series of posts, I have created a tiny set of tools which basically do exactly as the names imply.
While I admit, not quite hard to do, perhaps you’d even prefer to type things manually, but as mentioned in my previous post, for me it’s all about re-usability.

Requirements

In one of the upcoming installments of my VM Lab series, I will create a template VHD file, which will need to be set to Read Only in order to prevent changes to be made accidentally.
In another, I will need to copy a current Unattend.xml file, check if it was set to Read Only and if it was, remove that value so we can customize the contents.

So I made a small set of tools that did just that.

Functions

As the scripts aren’t too complex, but do server a solid purpose for the rest of the series, I’ve provided the code below.

BEWARE

These functions are meant for a test environment.
I’ve borrowed Jeffery Hicks‘ disclaimer, because it simply says it all:

DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED THOROUGHLY IN A LAB ENVIRONMENT.
USE AT YOUR OWN RISK.
IF YOU DO NOT UNDERSTAND WHAT THIS SCRIPT DOES OR HOW IT WORKS, DO NOT USE IT OUTSIDE OF A SECURE, TEST SETTING.

I’ve set the scripts to a max height as to not flood the page, but rest assured, everything’s there.
Please do note that functions might refer to other functions, this is intended as a complete toolset, not just 1 piece.

If you have questions on the techniques used or suggestions on how to improve something, please let me know in the comment section!

Get-ReadOnly

Set-ReadOnly

Remove-ReadOnly

 

Facebooktwitterredditlinkedinmail