Finding Servers Created within the Last Year

One of my customers recently asked me to generate a report showing all of the VMs that they had created within the last 12 months (ideally, broken down by OS), and then another showing the same for 24-12 months ago.  I did a bunch of digging around and couldn't find any attribute on the VMs that showed their creation date.  Some research revealed that the standard solution to this problem is to get-vievents for all of the VMs, then look at the date of the first event.

Unfortunately, this customer had performed a vCenter migration about a year ago, so our logs weren't intact for this purpose.  I was stumped, but one of the other admins came up with a good idea: look at the AD objects instead of the VM objects.  AD objects actually have a .whenCreated attribute, so we just need to grab them all and then find the ones for our desired timeframes.

Of course, that approach grabs all AD computers, including desktops.  We just needed a list of servers (we knew that all servers would be VMs), but since the AD computer objects have a ton of really useful attributes, filtering the results was a breeze!  In the end, we decided to grab all AD Computer objects that weren't Windows 7 or Windows 10 and weren't in the Workstations or Laptops OUs (for whatever reason, some of the desktop computer objects didn't list an OS, so we got those out of the list by also filtering by OU).

Using the script is pretty easy, just do it like this: get-newComputers.ps1 -startMonthsAgo X -endMonthsAgo Y

That will give you a list of all computer accounts created between X and Y months ago.  You can use the -notOS and -notOU parameters to specify arrays of strings for the script to ignore in their respective fields.  For example, -notOS @("XP","7","10") will exclude any computers that list Windows XP, Windows 7 or Windows 10 as their OS.  Similarly, -notOU @("workstations","laptops") will exclude any computers that are in the workstations or laptops OU.  Additionally, you can use the -outFile parameter to save the results to a CSV file (if you don't want to capture them to a variable).

As always, this script is provided as-is for educational purposes with no warranty or guarantee of any kind.  Test thoroughly and ensure that you fully understand any script before running it in your own environment, and although this worked for this customer in this specific environment, that doesn't mean that it'll work for you in yours.

After I generated the CSV files, I opened them up in Excel and used a quick pivot table to show counts for each OS.  The end result was a spreadsheet with a very approachable high level summary tab, and then some explicit data for the customer to browse through if they wanted more details about anything revealed in that summary.


Popular posts from this blog

Deleting Orphaned (AKA Zombie) VMDK Files

Clone a Standard vSwitch from one ESXi Host to Another

vCenter Server Appliance Crash due to Full /Storage/SEAT Partition