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

 

twitterredditlinkedinmail

VM Lab – Lab Folders

Lets get started…

First of all, I always prefer my lab to have the same layout and tend to use the same solutions, since they’re either best practice or the most logical approach for me.
Now in a Lab environment, this starts at the basics, creating a folder structure to put everything in, from VHDs, VMs to ISO files and templates.

Requirements

For my Lab I always want it to have the same folder structure.

This structure is as follows:

  • $Root\ISO
  • $Root\VHD
  • $Root\VHD\Template
  • $Root\VM

Structure

Now I wanted to have the following “solutions” for this requirement:

  • Get-LabFolder
    To see if the current folder [including all sub folders] actually already exists.
    The most annoying bit was to check if all the sub folders actually existed, which I bet can be done more elegantly, but I’ll need to check that at a later point.
  • New-LabFolder
    Create a new set of Lab folders in the provided Root.
  • Remove-LabFolder
    Take a wild guess 😉
    Mostly for my testing purposes, since I’ve not yet done Pester tests for all my scripts.

While it seems very basic, making tiny building blocks out of every solution, makes it so I can re-use these solutions at a later point.
This isn’t a “hard” solution, but for me the most important bit was getting the structure done right, making sure everything has a proper help function and is somewhat well documented/scripted.

In the process I also used a handy trick for a confirmation pop-up on the deletion, to let someone confirm they want to remove the folder structure, because gone = gone.

Functions!!

Here’s what most people come for.

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-LabFolder

New-LabFolder

Remove-LabFolder

 

twitterredditlinkedinmail

VM Lab – Introduction

Hey guys,

It’s been a bit quiet lately, some holiday time and most importantly a change of jobs!
As of July 1st I now work for OSC as an Infrastructure Specialist and will hopefully have more time to expand my knowledge and share this with the community.

The last few weeks I’ve been busy playing around with a solution in order to quickly create a Lab with VM’s.

While I know how to manually set them up and create machines, I had a somewhat ‘ideal’ method in mind and didn’t really want to stray from that idea.

I will finish up the solution this week hopefully, but already have a Proof Of Concept [POC] solution working as intended.
While this sounds all fancy, basically I have all the tiny building blocks ready as scripts.
It means I will need to finish writing all the help files, modifying them from scripts to functions and putting them all in a single module.

What does the solution do?

Here’s a quick overview of what my solution does:

  • Create [or checks if it exists] a default Hyper-V folder structure in place where you can store everything you require for your Lab
  • Create a default Hyper-V infrastructure in place which you can utilize for your Lab
  • Creates template VHD files on which you can base your Lab VM’s.
    This solution provides templates for the following Operating Systems:

    • Windows 8.1
    • Windows 10
    • Windows Server 2008R2 [Core + GUI]
    • Windows Server 2012R2 [Core + GUI]
    • Windows Server 2016 TP5 [Core + GUI]
  • Creates differencing disks based on the above template VHDs, which are ‘enhanced’ by custom Unattend.xml files specifying:
    • ComputerName
    • UserName
    • Password
    • Organization
    • IP Address
    • DNS Server Address
    • Gateway Address

Once you have the template VHD files created [this takes the longest and only needs to be done once], it takes SECONDS to configure and start up your custom Lab VM

LabMachine_PowerShell

What next?

As mentioned above, I will need to update the help files, fine tune certain bits and convert the solution from separate scripts to functions in a module.
Now I’m not expecting this to take ages, but I want to make sure I don’t accidentally break my current solution.

In the coming time I will try and break down all created functions and provide the entire code.

To be continued! 🙂

twitterredditlinkedinmail