Virtually Sober

If there is free booze and Virtualization; I'm there!

Tag Archives: PowerShell

Creating a vSphere Change Management DB for free – Step 4 of 4

For my final blog post in the 4-part series on how to create a vSphere Change Management Database for free, I’m going to show you how to prune the data. If you missed the first 3 posts check them out here:

Step 1 – Creating the SQL Database
Step 2 – Inserting data into the SQL Database
Step 3 – Querying the SQL Database

Depending on the size of your vSphere environment or your data retention policies you probably don’t want to log vCenter settings indefinitely. Because we designed the database to always contain a RecordID in each table along with a LastUpdated datetime, we can use this to prune the data.

Read more of this post

Creating a vSphere Change Management DB for free – Step 3 of 4

In my previous 2 blog posts I took you through creating a vSphere Change Management Database, how to insert data using PowerCLI, and in this post, I’ll show you some example queries you can run once you have the data. If you missed the first 2 posts check them out here:

Step 1 – Creating the SQL Database
Step 2 – Inserting data into the SQL Database

There are probably hundreds of different things you can derive from the data captured. So here is just a sample of what I’m going to show you:

  • Show all configurations of a VM across all data logged
  • Taking oldest date available and showing all VM configs on that datetime
  • Taking the most recent data available and showing total VM size provisioned and used (useful for Rubrik sizing)
  • Using the oldest and most recent VM used size to calculate the total VM used storage growth % (also useful for Rubrik sizing!)
  • Show all VMDisk and VMNIC configurations for a VM
  • Show all configurations for a VMDK or VMNIC
  • Show all configurations for a Port Group on a host
  • Show all configurations of a Cluster and Host
  • Taking the oldest date available and showing all original Cluster and Host configs
  • Show all current and historical stats for a Datacenter (including cluster, host and VM counts etc)

Read more of this post

Creating a vSphere Change Management DB for free – Step 2 of 4

In the last blog we created a SQL database in which to store data from PowerCLI in order to create a vSphere Change Management Database for free. If you missed it, check it out here:

Step 1 – Creating the SQL Database

In this second post we are now going to insert data into the database and configure it to run on a schedule. To do this we are first going to use a PowerCLI cmdlet with variables to store the vSphere data, then we will use ForEach to insert each row of data into a corresponding SQL table row.

Read more of this post

Working with SQL databases using PowerShell

One of the things I love about PowerShell is the sheer number of use cases you can address. A perfect example is working with SQL databases. If you think you need to wait for a DBA to give you data from a SQL database then you’d be wrong. You can use SELECT queries to pull data directly into PowerShell from any SQL database and not only that, you can also INSERT, UPDATE, DELETE or whatever else you desire, all from the comfort your scripts using invoke-sqlcmd in the Sqlserver PowerShell module. This also means you can now store data from your PowerShell scripts in SQL for long-term reporting, configuration management, you name it.


Read more of this post

REST API changes in Zerto Virtual Replication 5.0 U3

Since my first post back in 2014, many of the example scripts that I’ve shared integrate with Zerto using their bolt-on REST APIs. After 4 years of stability, in 5.0 U3, Zerto changed the requirements of the authorization header to require the content type in addition to the session token as a “security” feature.

Unfortunately, this means that any Zerto script you have downloaded from my blog, customized, or written, needs to be edited to continue working after the upgrade. Without any modification, your REST API calls to Zerto won’t even give you an error, they will just return null. Pretty annoying huh? I’ll be honest in that I was completely livid when I found out. To me, this looks like a pointless change to fix a problem that didn’t exist while creating a heap more by how it is was implemented and communicated.

On top of this, the Zerto API documentation leaves a lot to be desired as it hasn’t even been updated (as of 06/25/17) to reflect the new requirements! But that’s why I’m here to help. So how do you go about fixing your Zerto scripts?

Read more of this post

Logging Zerto Sync States Using REST APIs & PowerShell

A few days ago a Zerto prospect reached out to me on LinkedIn with an interesting script request and there is nothing like a good challenge to get me motivated to pull out PowerShell ISE! With over 1000 VMs to protect their key requirement was to log the start and end time of initial syncs. While the ZVR GUI shows when a VPG was created, it doesn’t show when the initial sync finishes:

This is certainly an annoying omission and the lack of specific data points isn’t limited to just Zerto; how many other solutions do you use in your environment where you want to know/see something that just isn’t there for seemingly no logical reason? Of course, you could contact your vendor account manager, raise a feature request, wait 3-6 months and cross your fingers that it was even considered let alone in the product. Or you can use the REST APIs to get the data yourself, today, in minutes!

Read more of this post

Automated bulk IP address reconfiguration with Zerto Virtual Replication

When configuring IP address changes in Zerto Virtual Replication (ZVR) one common challenge is data entry. Yes, it’s certainly easy to configure the new IP addresses in the GUI, but when you are protecting hundreds of VMs with hundreds of vNICs then using the GUI can become a problem. Not only will it take you a long time to configure each vNIC one by one, but you are introducing the risk of human error.


To solve this challenge I created 2 PowerShell scripts to fully automate re-IP addressing in bulk. The first script “ZVR Bulk Re-IP Export v1.ps1” exports a list of every protected VM vNIC to a CSV with a column for each configuration item possible. You will need to protect every VM first for its vNIC info to be exported, edit the variables at the top of script for your environment, then run it to get the below output: Read more of this post

Catching Ransomware infections with a Honeypot script & integration into Zerto Virtual Replication

Through my work at Zerto I’ve delivered multiple presentations and webinars on ransomware and how Zerto enables you to recover VMs, files and folders from seconds before the data was encrypted to minimize data loss and avoid having to pay a ransom. One question I’ve often been asked is how do I know what point in time my files were encrypted? And in one recent presentation a customer told me that their user didn’t tell IT until 3 days after the infection had occurred!

This got me thinking on how we could alert on this which led me to evaluate the different ransomware honeypot example scripts available online. These scripts validate a file placed on a user mapped share, where everyone has write permissions, against a gold or witness copy to catch the ransomware infection then perform a set of actions when found. In testing the multiple examples I struggled to find one that coped with the file itself being changed, I.E the extension changing, that ran consistently and none indicated this alert in the Zerto journal so I decided to write an example that did all of this and more. Read more of this post

Scripting a Recovery Plan

To protect VMs with Zerto they need to be placed into Virtual Protection Groups (VPGs) which are consistency groupings of VMs that are typically configured on a per application basis. A VM can only exist in 1 VPG at once, you can only failover the entire VPG and you can define the boot order of VMs inside each VPG.

A common request I receive is to specify a boot order between VPGs (a recovery plan) so that you can bring VPGs online in a specified order with time delays and pre/post failover scripts. A perfect use case is bringing Application 1 (I.E a Finance DB) online before Application 2 (I.E a CRM). You could work around this by placing all the VMs that form both applications in the same VPG, but this then removes the fidelity of failing over an individual application in the cases of logical failures. Another use case is running a site wide script that should only be initiated when failing over everything.

Based on this requirement I decided to create the Recovery Plan script. Read more of this post

Adding Zerto cmdlets to a script

In order to run Zerto cmdlets inside a script you have to add the snapin. This is easily done with the following command:

add-pssnapin Zerto.PS.Commands

Read more of this post