Lately I have been working on scripting for a lot of different products. While doing so, I decided to try incorporating William Lam’s scripts for automating the vCAC 6 IAAS server.

I already had my own scripts that did the vCAC6 Pre-req automation and a personal script that automated the install of SQL server. So between what I already had, and part of what William had created, I set out to do a little more automation. However, I ran into some issues when running William’s script. I realized it was something I had done since others had said that his script worked great (yes, I did edit past the ‘DO NOT EDIT BELOW THIS POINT’ comment…)

The issue arose when installing the DEM worker, agents, and vCAC Database. I decided I wanted to Tail the log that was being created to see what was going on in real-time. In Linux, tailing a log is easy, but I had never done this in Windows before, a quick google search led me to an ‘almost as easy’ solution. If you know where the log file is created, open a PowerShell session and type:

Get-Content -Path "C:\pathoflogfile" -Wait

This will enable you to watch in real-time as the logfile gets updated. By using this I was able to see at what point I had messed up the original install script and tweaked it to where it worked again. It’s much easier to tail the log than have to go into a logfile with thousands of lines of code and search for issues after the fact.

As I have had to start learning Powershell over the last few months, I decided I would start posting some of the helpful things I had learned in hopes that others will not have to search as hard for the same information in the future.

There are many reasons why you may want to use XML with Powershell. You may want to store information in Powershell or you may want to read information from PowerShell. Either reason is a good one. I did both. One reason I used XML files was because my script would kick off a half-dozen jobs as well as other Powershell scripts. Using an XML file made it easy to pass information between the jobs and other scripts, which allowed for it to be more dynamic.

So, how is it done? there are several ways depending on how you write your XML.

Reading XML

The first format of XML I will show you uses ‘add key’ and the value within the same brackets. There is nothing wrong with this and it actually can be quite helpful to write the XML like this, especially if you do a ‘foreach’ statement in your PowerShell code.

<?xml version="1.0"?>
<!--SDDC ToolKit Config-->
<configuration>
  <General>
    <add key="VCName" value="192.168.1.40" />
    <add key="VCUser" value="root" />
    <add key="VCPassword" value="vmware" />
  </General>
</configuration>

Now, to read this in PowerShell you must first tell your session you want to read XML. This is done with the code below:

[xml]$variablehere = Get-Content (locationoffile)

PowerShell requires the [xml] so that it knows what language it is going to read. You must then assign a variable name for the xml file. the ‘Get-Content’ command is then used and you must specify the location of the file (of course!). So, that being said I may write the code like this:

$configxml = ("c:\temp\configfile.xml")
		[xml]$MyConfigFile = Get-Content ($configxml)

ok, great. So now powershell can read our XML file. now how do we use the values found in the XML file in our PowerShell session?

Retrieving Values from the XML file

Using the example above that uses the add key commands, we would search for the target values like this:

foreach($item in $MyConfigFile.configuration.General.add)
				{
			if($item.key -eq "VCuser")
				{$VCUser = $item.value}
			if ($item.key -eq "VCPass")
				{$VCPass = $item.value}
				}

so what this does is it takes the variable for reading the XML file ($MyConfigFile) and by specifying the section of the XML to look in (.configuration.General.add (look back in the XML example above and you’ll see that the sections are in the same order in the Powershell script)) you can then use an ‘if’ or a ‘switch’ to return the value and assign it to a variable.

Is there an easier way?

Like almost everything in this world, there is always more than one way to skin a cat. Below is another example that doesn’t require the use of ‘if’ statements or ‘switch’es.

You will note that this part of my XML is different in that the name of the object is in one bracket and the value is contained between the opening and closing of the object (like what you would see in HTML)

<POST>
    <PriDNS>192.168.1.80</PriDNS>
    <SecDNS></SecDNS>
    <NTP>192.168.1.80</NTP>

We can then reference each object by starting with our XML variable and then working our way through our XML hierarchy to the desired object:

$MyConfigFileloc = ("c:\temp\ConfigFile.xml")
[xml]$MyConfigFile = (Get-Content $MyConfigFileLoc)

$PriDNS  = $MyConfigFile.Configuration.Post.DNS1 
$SecDNS = $MyConfigFile.Configuration.Post.DNS2
$NTP = $MyConfigFile.Configuration.Post.NTP1 

Saving values to XML

Saving values is just as easy as reading values from the XML files. All you have to do is change what is on each side of the ‘=’. To save back to the file you could do this:

$MyConfigFileloc = ("c:\temp\ConfigFile.xml")
[xml]$MyConfigFile = (Get-Content $MyConfigFileLoc)

$MyConfigFile.Configuration.Post.DNS1 = $PriDNS
$MyConfigFile.Configuration.Post.DNS2 = $SecDNS
$MyConfigFile.Configuration.Post.NTP1 = $NTP

$SDTConfigFile.Save("$MyConfigFileLoc")	

You must then use the ‘.Save(XMLfile)’ to make sure the new values are saved and not discarded.

once the values are saved, you can use them across any PS Sessions, Jobs, Scripts, or any other program that you may choose to share data with.

Depending on how much you spent creating your lab, you may find yourself running out of disk space sooner rather than later. This can be a frustrating experience, so I decided to do a quick post about several ways you can deal with this issue.

1. Create Linked Clones

When working with limited disk space (especially if it is on SSD’s), you will want to create a gold/master VM that you can save as a template as well as use as the base for your linked clones. If you don’t know what Linked-Clones are, essentially you are creating a pure “STANDARD” VM that can be used as a base VM for other future virtual machines. When you need another VM, instead of creating a new full VM that is, lets say, 40GB, you create a linked-clone, which will reference the base bits of your STANDARD VM that you created earlier. Your disk size will only grow with the deltas between the standard and the new VM. When you have your base VM’s running on SSD you can run many more VMs from the same standard bits without seeing performance degradation. If you usually have 5+ Server 2008 VMs running in your lab, you are essentially cutting your disk usage down by  (the size GB of the installation of server 2008 with updates * # of VMs running). This savings adds up quickly.

2. Deduplication

deduplication

Another way to deal with the issue of low disk space is to use deduplication. There are several virtual appliances out there that you can use for free that offer deduplication. Deduplication speaks for itself in that these appliances will look through the blocks of data in their datastores and deduplicate any bits that show up more than one. Pointers are placed that allow the data to continue being usable while keeping your disk usage to an absolute minimum. I have personally tried Nexentastor and used that for quite a while. If you are backing up your VM’s, almost all VM backup solutions integrate deduplication into their products: Arkeia, Veeam, VMturbo, etc.

3. Be frugal in your storage use

Many of you, like me, probably have multiple copies of the same downloads and ISO’s scattered between multiple computers, flash drives, NAS’s, etc. I find myself being sloppy time and time again by pulling an installer into a VM and after using it, I DON’T DELETE IT! yeah, that adds up too! Create a network share that is accessible in your lab and make sure to keep your files there. I prefer to add an NFS export as well and connect it to my hosts so that my ISOs can be mounted from there without having to upload any of them to another datastore.

4. Use Thin Provisioning

This should have been the very first bullet. As I started writing this I figured that this would be a no-brainer, but then I decided, since it really is important, to add it in anyways. There are very few reasons that could be keeping you from running everything thin. If you have all the storage your heart desires then be my guest. Chances are, if you are reading this blog post it means that you are not one of those people :).

5. Purchase more storage

Last but not least, if the above 4 options still do not give you the amount of flexibility and wiggle-room you need, then it’s probably pretty safe to say that you didn’t have enough space to begin with. Decide if you want to install more storage locally or invest in a NAS. I prefer the Synology NAS’s hands-down, no questions asked. Yes, they are more expensive, but you get what you pay for. If you do purchase a NAS you will also want to decide if you are going for extra speed or larger drives. I prefer a mixture of SATA Western Digital Reds with a few SSD’s. The Reds hold installers and other VM’s like my active directory VM that doesn’t do much data transfer.

 

Hopefully this article has been beneficial. What have you done to deal with limited disk space in your labs?

As more of you start moving towards vSphere 5.5 (which I strongly recommend), you should take into consideration how you plan on upgrading your products. Continue reading “vSphere 5.5 Upgrade Order” »

I just published an post today on the vSphere blog with a script that will automate the vCAC prerequisites, saving you time and effort when deploying the latest version of vCloud Automation Center. To see the article and download the script click HERE.

vCAC Automated Installation Script

 

If you have been using vSphere for any length of time, you have already come to know what a God-send and how essential VMware Tools is. For the majority of admins, being able to install VMware Tools using the Thick client drop-down and now from the web-client, is sufficient. However, there are times that you may want to have this scripted. To do a silent install of VMware Tools on a Windows VM you can do the following:

  • Copy the VMware Tools Installer to a local or shared folder
    • Note: There are 2 different installers: Setup.exe and Setup64.exe Choose according to the corresponding OS
  • Open Command Prompt
  • Browse to the folder that includes the setup file
  • type .\setup64.exe /s /v “/qn reboot=r”

The /qn means it will be a silent (quiet) installation, there will be no GUI.

reboot=r will keep your VM from restarting after the installation completes

s – silent execution

v – sends all parameters directly to the msi file.

 

Hope this helps!

While working on some tasks within my VI I came across the need to create a .flp image for a VM. I’d used some virtual floppy images in the past but had yet to actually need to create my own. After browsing google results for virtual floppy image creators, and trying about 5, the best, easiest, and most light-weight program I found was BFI – Build Floppy Image .   Surprisingly it was last updated on November 4, 2002, it still works like a charm though. BFI is a commandline utility (if you’re not big into CLI don’t freak out, it’s easy). The file itself is 90k and running it from command prompt will show you available commands. BFI Screenshot   When you have all the files you want in your virtual floppy image are ready, run BFI and type the commands you want. The easiest example I can give you that has worked well for me is: bfi -f=c:\temp\outputfilename.flp c:\temp\nameoffolderwithfilestocopy IT’s THAT SIMPLE! once you hit ‘Enter’ the image will be created and you can upload it to a datastore and connected it as a virtual floppy disk to any of your VM’s. Enjoy!

While working on some tasks within my VI I came across the need to create a .flp image for a VM. I'd used some virtual floppy images in the past but had yet to actually need to create my own. After browsing google results for virtual floppy image creators, and trying about 5, the best, easiest, and most light-weight program I found was BFI - Build Floppy Image .   Surprisingly it was last updated on November 4, 2002, it still works like a charm though. BFI is a commandline utility (if you're not big into CLI don't freak out, it's easy). The file itself is 90k and running it from command prompt will show you available commands.   When you have all the files you want in your virtual floppy image are ready, run BFI and type the commands you want. The easiest example I can give you that has worked well for me is: bfi -f=c:\temp\outputfilename.flp c:\temp\nameoffolderwithfilestocopy IT's THAT SIMPLE! once you hit 'Enter' the image will be created and you can upload it to a datastore and connected it as a virtual floppy disk to any of your VM's. Enjoy!

Floppy Image Creator

Size
Ease of Use
Support
Functionality
Cost

Simple

This program is simple to use and quick to install and learn. The best part, IT'S FREE!

User Rating: 4.29 ( 3 votes)
83
Bad Authentication data