Building My Orion Lab

So, I normally need to build a Lab for my SolarWinds Orion.  If I’m doing this on my own machine and don’t have the luxury of a Windows Deployment Server (WDS), and I’ve built a custom hard drive for my Windows Servers, then I use a PowerShell script to do this work for me. (Seeing a pattern here?)My script is broken into a few stages.  If you’ve seen my other scripts then, you’ll notice that I’ve used a similar format in the past.  In this one, I really only have two regions: the Variable Definition and the actual work.

First we have the variable definition…

#region Variable Definition
#------------------------------------------------------------------------------------------
$vSwitch        = "vSwitch-Ethernet"
$StartupMemory  = 1GB
$MinimumMemory  = 512MB
$MaximumMemory  = 4GB
$ProcessorCount = 2
$PowerOn        = $false
$TemplateVhd    = "C:\Hyper-V\VHDs\Template_W2K12R2_2014Q2.vhdx"

<# VMs:
    KMSSWOMPE01v  - KMSigma Lab / SolarWinds Orion / Main Polling Engine    / 01 / Virtual
    KMSSWOMNTA1v  - KMSigma Lab / SolarWinds Orion / NetFlow Database       / 01 / Virtual
    KMSSWOAPE01v  - KMSigma Lab / SolarWinds Orion / Add'l Polling Engine   / 01 / Virtual
    KMSSWOAWS01Av - KMSigma Lab / SolarWinds Orion / Add'l Website (A-Node) / 01 / Virtual
    KMSSWOAWS01Bv - KMSigma Lab / SolarWinds Orion / Add'l Website (B-Node) / 01 / Virtual
#>
$NewVMs = "KMSSWOMPE01v", "KMSSWONTA01v", "KMSSWOAPE01v", "KMSSWOAWS01Av", "KMSSWOAWS01Bv"

# Counters for the Progress Bar
$i = 0; $iCount = $NewVMs.Count

#------------------------------------------------------------------------------------------
#endregion Variable Definition

I’ve outlined the things that don’t change – the Virtual Switch Name, the Memory Settings, CPU Count, if I want to Power it on and the Path to the Template Hard Drive.

Then it’s a little more specific to this particular script.  I list out the new VM Names – I’m creating an Orion Main Polling Engine (MPE), an Add’l Polling Engine (APE), two Add’l Web Servers (AWS), and one machine for the FastBit NetFlow Database (NTA).  Collectively, the APE’s and AWS’s are considered Scalability Engines.  If you have a large scale deployment and you aren’t using them, then you definitely should consider them.

I’ve already got a SQL Server, so I’m not building that.

Finally, we setup variables ($i and $iCount) for creating the progress bar.

Now it’s time for the real work of the script.  We need to do the following:

  1. Build the “shell” of the VM with the name, no Hard Drive, Startup Memory, and the Switch.
  2. Update the Processor Count (since we want 2 and not the default 1).
  3. Configure the Dynamic Memory
  4. Copy the Template Hard Drive.
  5. Add this disk to the Virtual Machine
  6. Set the Boot Order of the Machine (Disk first, then NIC)
  7. Finally, if we want to Power On the Machine, do so.

What’s that look like in script form?

# Let's build them VM's
ForEach ( $NewVM in $NewVMs )
{
    Write-Progress -Activity "Creating Virtual Machines" -CurrentOperation "Creating $NewVM" -Status "Creating Virtual Machine" -PercentComplete ( ( $i / $iCount ) * 100 )
    $VM = New-VM -Generation 2 -MemoryStartupBytes $StartupMemory -Name $NewVM -NoVHD -SwitchName $vSwitch
    
    Write-Progress -Activity "Creating Virtual Machines" -CurrentOperation "Creating $NewVM" -Status "Set Processors" -PercentComplete ( ( $i / $iCount ) * 100 )
    $VM | Set-VM -ProcessorCount $ProcessorCount
    
    Write-Progress -Activity "Creating Virtual Machines" -CurrentOperation "Creating $NewVM" -Status "Set Memory" -PercentComplete ( ( $i / $iCount ) * 100 )
    $VM | Set-VMMemory -StartupBytes $StartupMemory -MinimumBytes $MinimumMemory -MaximumBytes $MaximumMemory -DynamicMemoryEnabled:$true
    
    Write-Progress -Activity "Creating Virtual Machines" -CurrentOperation "Creating $NewVM" -Status "Copy O/S Disk" -PercentComplete ( ( $i / $iCount ) * 100 )
    $VhdPath = Join-Path -Path $( ( Get-VMHost ).VirtualHardDiskPath ) -ChildPath "$( $NewVM )_C.vhdx"
    Start-BitsTransfer -Source $TemplateVHD -Destination $VhdPath -Description "Copying Template Hard Drive"
    
    Write-Progress -Activity "Creating Virtual Machines" -CurrentOperation "Creating $NewVM" -Status "Add O/S Disk" -PercentComplete ( ( $i / $iCount ) * 100 )
    $VM | Add-VMHardDiskDrive -Path $VhdPath
    
    Write-Progress -Activity "Creating Virtual Machines" -CurrentOperation "Creating $NewVM" -Status "Set Boot Order" -PercentComplete ( ( $i / $iCount ) * 100 )
    $VM | Set-VMFirmware -BootOrder ( $VM | Get-VMHardDiskDrive ), ( $VM | Get-VMNetworkAdapter )
    
    if ( $PowerOn )
    {
        Write-Progress -Activity "Creating Virtual Machines" -CurrentOperation "Creating $NewVM" -Status "Powering On" -PercentComplete ( ( $i / $iCount ) * 100 )
        $VM | Start-VM
    }
    $i++
}

And there you have it.  A simple script to build however many machines you want.  There’s an assumption or two with this of course.  I’m assuming that I want all the machines identical (yes), and second that you are installing all the various parts of SolarWinds Orion (for me – yes).  Also, this script does not error trap for hard drives with the same name.

I’m thinking that my next post will involve using differencing disks instead of copies of my template hard drive.

Until next time everyone – Ramble on!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.