Testing Virtual Machine Network Connectivity En-Masse
Last year, I wrote a post with a quick one-liner about how to ping all VMs on a given ESXi host. Since then, I've been doing a lot of work with vSphere 6 upgrades, which has involved migrating many VMs between various switches. As part of that process, I like to have an established basic test that I can run before and after the migration, so that I can record that the migration was successful.
So, needless to say, I've expanded on that old one-liner a little bit... and now it's a full blown script. I've built this script based around my migration validation use case, and so it has some very specific behaviors based around that. It accepts four parameters, but really only two of them are required: -vmHost and -results. As you certainly expect, -vmHost is the name of the host on which you want to ping all VMs and -results is a path to a file where the script will store its results (I just use a .txt file, myself).
When the script is executed for the first time, it pulls the list of all VMs on the specified host and then checks that they're powered on. Assuming that each VM is powered on, then it attempts to ping the VM by its VMTools hostname. If that fails, the script reports that and logs the name of the VM in the -results file.
The next time that the script is run (really, any time that the specified -results file already exists), its behavior changes slightly. If a given VM fails to ping on this subsequent run, the script checks the -results file from the previous execution. If the VM is listed as having failed to ping before, the script makes note that this was an expected failure. If the VM is not on the list of previous failures, then it both highlights that line in red and returns a list of all new failures at the end (which could easily be redirected into a variable or an output file or whatever).
The two optional switches are mutually exclusive: -overwrite and -append. They change the scripts behavior, if it finds that the -results file already exists. The -overwrite switch tells the script to run as if this were its first execution, overwriting the existing results file with a new "first run" execution (so it doesn't compare against those results and just overwrites the file). The -append switch tells the script to run as if this were its first execution, but append the new results to the old ones rather than overwriting completely.
Using the script is pretty easy:
test-ping.ps1 -vmhost <ESXi hostname> -results <path to results file> [-append | -overwrite]
As always, this script is provided as is, for educational purposes... use at your own risk... basically, this worked for me in my particular situation, but that is no guarantee that it will work anywhere else! Test thoroughly, and please let me know about any fixes that you make!
So, needless to say, I've expanded on that old one-liner a little bit... and now it's a full blown script. I've built this script based around my migration validation use case, and so it has some very specific behaviors based around that. It accepts four parameters, but really only two of them are required: -vmHost and -results. As you certainly expect, -vmHost is the name of the host on which you want to ping all VMs and -results is a path to a file where the script will store its results (I just use a .txt file, myself).
When the script is executed for the first time, it pulls the list of all VMs on the specified host and then checks that they're powered on. Assuming that each VM is powered on, then it attempts to ping the VM by its VMTools hostname. If that fails, the script reports that and logs the name of the VM in the -results file.
The next time that the script is run (really, any time that the specified -results file already exists), its behavior changes slightly. If a given VM fails to ping on this subsequent run, the script checks the -results file from the previous execution. If the VM is listed as having failed to ping before, the script makes note that this was an expected failure. If the VM is not on the list of previous failures, then it both highlights that line in red and returns a list of all new failures at the end (which could easily be redirected into a variable or an output file or whatever).
The two optional switches are mutually exclusive: -overwrite and -append. They change the scripts behavior, if it finds that the -results file already exists. The -overwrite switch tells the script to run as if this were its first execution, overwriting the existing results file with a new "first run" execution (so it doesn't compare against those results and just overwrites the file). The -append switch tells the script to run as if this were its first execution, but append the new results to the old ones rather than overwriting completely.
Using the script is pretty easy:
test-ping.ps1 -vmhost <ESXi hostname> -results <path to results file> [-append | -overwrite]
As always, this script is provided as is, for educational purposes... use at your own risk... basically, this worked for me in my particular situation, but that is no guarantee that it will work anywhere else! Test thoroughly, and please let me know about any fixes that you make!
Check out the script on Github!
Comments
Post a Comment
Sorry guys, I've been getting a lot of spam recently, so I've had to turn on comment moderation. I'll do my best to moderate them swiftly after they're submitted,