Create a Test Environment for PowerCLI Scripts

Background:

One of the geeks wanted help using the Networking and iSCSI Configuration starter scripts from our blog post earlier in the year; Starter Scripts for ESXi Hosts.

A few days after getting the script tuned for their needs, they mentioned not having any hosts available to test the script, and they were caught off guard when I asked why they weren’t using a few nested ESXi hosts to test the script prior to their new hosts being available.

Reasons to use nested hosts, for testing scripts only:

  • Nested hosts restart faster than physical hosts.
  • Snapshot their working state and revert back to that state after testing your script(s).
  • Access DCUI of the host through console in vCenter.
    • You may make changes to the management network of the host and would lose access without an out-of-band solution.

This post will focus on taking a snapshot of the nested hosts’ working state and reverting to that state after testing your script(s).

The PowerCLI script, “revert_test_vms.ps1” referenced in this post, is available on our public GitHub repo: https://github.com/humbledgeeks/amount

Script Information: “revert_test_vms.ps1”
  • Stop the nested hosts.
  • Revert to the preferred snapshot.
  • Start the nested hosts.
Assumptions:
  • Create two, or three, nested ESXi hosts.
    • We gave each nested host:
      • vCPU = 2
      • vRAM = 6GB
      • vHDD = 80GB
      • vNIC = 2, you can add more NICs to match the physical hosts in your environment.
  • Place those hosts in a folder named “test-scripts”.
    • If you prefer a different name, you will need to change the ‘-Location’ value in the PowerCLI script to match that folder name.
  • Configure the management network on each host to make them accessible after reverting to their snapshot.
  • Shut down the nested hosts after the management network configuration is completed.
  • Download the “revert_test_vms.ps1” script or copy its contents into PowerShell.
Walkthrough: Taking a snapshot of the nested hosts.
Create a Test Environment
Select your nested hosts.
Create a Test Environment
Right-click an empty area on one of the nested hosts.
Create a Test Environment
Click on “Snapshots”.
Create a Test Environment
Click on “Take Snapshot…”.
Create a Test Environment
Type a name for the snapshot.
– We used “2023-06-23T2015”
Create a Test Environment
Click on “Create”.
Create a Test Environment
Right-click an empty area on one of the nested hosts, after the snapshots are completed.
Create a Test Environment
Click on “Power On”.
Test your script(s) on the nested hosts!
Walkthrough: Revert your nested hosts to their working state.
Create a Test Environment
Run the “revert_test_vms.ps1” script.
Create a Test Environment
Login to vCenter.
– Enter your credentials and click “OK”.
Create a Test Environment
The nested hosts have reverted to their snapshot and can be used for testing, again!
– You will see prompts that each nested host is being stopped, reverted, and started.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top