Taking Control of VM Sprawl (Part 17)

If you would like to read the other parts in this article series please go to:

This article series has become one of the longest series that I have ever written, but it’s almost finished! At the end of the previous article, I mentioned two main tasks that needed to be completed. First, the script needs to be extended to cover a full year. Second, the data from the script needs to be added to a chart. Fortunately, both of these are relatively simple tasks. We have already done all of the hard stuff.

So here is my plan for this article. I want to start out by giving you the source code for a script that collects a full year’s worth of virtual machine creation and deletion data. I’m not going to go into a lot of detail about how the script works, because the mechanics of it are identical to what we have already been working on. The script has simply become a lot longer.

The other thing that I want to do in this article, is to show you a couple of tricks that you can use to make this script a bit more useful in the real world.

So with that said, here is the script:

Function Get-MyData($Server){

#Function to get VM log data information

$MySession = New-PSSession -ComputerName $Server

#Initialize Variables

Invoke-Command -Session $MySession -ScriptBlock {

 

                #January

                $NumJanCreateEvents = ‘0’

                $JanCreateEvents = ”

                $NumJanDeleteEvents = ‘0’

                $JanDeleteEvents = ”

                $JanStartDate = ‘01/01/2016 12:00:00 AM’

                $JanEndDate = ‘01/30/2016 11:59:59 PM’

 

                #February

                $NumFebCreateEvents = ‘0’

                $FebCreateEvents = ”

                $NumFebDeleteEvents = ‘0’

                $FebDeleteEvents = ”

                $FebStartDate = ‘02/01/2016 12:00:00 AM’

                $FebEndDate = ‘02/29/2016 11:59:59 PM’

 

                #March

                $NumMarCreateEvents = ‘0’

                $MarCreateEvents = ”

                $NumMarDeleteEvents = ‘0’

                $MarDeleteEvents = ”

                $MarStartDate = ‘03/01/2016 12:00:00 AM’

                $MarEndDate = ‘03/30/2016 11:59:59 PM’

 

                #April

                $NumAprCreateEvents = ‘0’

                $AprCreateEvents = ”

                $NumAprDeleteEvents = ‘0’

                $AprDeleteEvents = ”

                $AprStartDate = ‘04/01/2016 12:00:00 AM’

                $AprEndDate = ‘04/30/2016 11:59:59 PM’

 

                #May

                $NumMayCreateEvents = ‘0’

                $MayCreateEvents = ”

                $NumMayDeleteEvents = ‘0’

                $MayDeleteEvents = ”

                $MayStartDate = ‘05/01/2016 12:00:00 AM’

                $MayEndDate = ‘05/31/2016 11:59:59 PM’

 

                #June

                $NumJunCreateEvents = ‘0’

                $JunCreateEvents = ”

                $NumJunDeleteEvents = ‘0’

                $JunDeleteEvents = ”

                $JunStartDate = ‘06/01/2015 12:00:00 AM’

                $JunEndDate = ‘06/30/2015 11:59:59 PM’

 

                #July

                $NumJulCreateEvents = ‘0’

                $JulCreateEvents = ”

                $NumJulDeleteEvents = ‘0’

                $JulDeleteEvents = ”

                $JulStartDate = ‘07/01/2015 12:00:00 AM’

                $JulEndDate = ‘07/31/2015 11:59:59 PM’

 

                #August

                $NumAugCreateEvents = ‘0’

                $AugCreateEvents = ”

                $NumAugDeleteEvents = ‘0’

                $AugDeleteEvents = ”

                $AugStartDate = ‘08/01/2015 12:00:00 AM’

                $AugEndDate = ‘08/31/2015 11:59:59 PM’

 

                #September

                $NumSepCreateEvents = ‘0’

                $SepCreateEvents = ”

                $NumSepDeleteEvents = ‘0’

                $SepDeleteEvents = ”

                $SepStartDate = ‘09/01/2015 12:00:00 AM’

                $SepEndDate = ‘09/30/2015 11:59:59 PM’

 

                #October

                $NumOctCreateEvents = ‘0’

                $OctCreateEvents = ”

                $NumOctDeleteEvents = ‘0’

                $OctDeleteEvents = ”

                $OctStartDate = ‘10/01/2015 12:00:00 AM’

                $OctEndDate = ‘10/31/2015 11:59:59 PM’

 

                #November

                $NumNovCreateEvents = ‘0’

                $NovCreateEvents = ”

                $NumNovDeleteEvents = ‘0’

                $NovDeleteEvents = ”

                $NovStartDate = ‘11/01/2015 12:00:00 AM’

                $NovEndDate = ‘11/30/2015 11:59:59 PM’

 

                #December

                $NumDecCreateEvents = ‘0’

                $DecCreateEvents = ”

                $NumDecDeleteEvents = ‘0’

                $DecDeleteEvents = ”

                $DecStartDate = ‘12/01/2015 12:00:00 AM’

                $DecEndDate = ‘12/31/2015 11:59:59 PM’

 

                }

 

# January 2016

$JanCreateEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13002;StartTime=$JanStartDate;EndTime=$JanEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumJanCreateEvents = $JanCreateEvents.count

$JanDeleteEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13003;StartTime=$JanStartDate;EndTime=$JanEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumJanDeleteEvents = $JanDeleteEvents.count

 

# February 2016

$FebCreateEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13002;StartTime=$FebStartDate;EndTime=$FebEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumFebCreateEvents = $FebCreateEvents.count

$FebDeleteEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13003;StartTime=$FebStartDate;EndTime=$FebEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumFebDeleteEvents = $FebDeleteEvents.count

 

# March 2016

$MarCreateEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13002;StartTime=$MarStartDate;EndTime=$MarEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumMarCreateEvents = $MarCreateEvents.count

$MarDeleteEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13003;StartTime=$MarStartDate;EndTime=$MarEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumMarDeleteEvents = $MarDeleteEvents.count

 

# April 2016

$AprCreateEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13002;StartTime=$AprStartDate;EndTime=$AprEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumAprCreateEvents = $AprCreateEvents.count

$AprDeleteEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13003;StartTime=$AprStartDate;EndTime=$AprEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumAprDeleteEvents = $AprDeleteEvents.count

 

# May 2016

$MayCreateEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13002;StartTime=$MayStartDate;EndTime=$MayEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumMayCreateEvents = $MayCreateEvents.count

$MayDeleteEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13003;StartTime=$MayStartDate;EndTime=$MayEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumMayDeleteEvents = $MayDeleteEvents.count

 

# June 2015

$JunCreateEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13002;StartTime=$JunStartDate;EndTime=$JunEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumJunCreateEvents = $JunCreateEvents.count

$JunDeleteEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13003;StartTime=$JunStartDate;EndTime=$JunEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumJunDeleteEvents = $JunDeleteEvents.count

 

# July 2015

$JulCreateEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13002;StartTime=$JulStartDate;EndTime=$JulEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumJulCreateEvents = $JulCreateEvents.count

$JulDeleteEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13003;StartTime=$JulStartDate;EndTime=$JulEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumJulDeleteEvents = $JulDeleteEvents.count

 

# August 2015

$AugCreateEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13002;StartTime=$AugStartDate;EndTime=$AugEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumAugCreateEvents = $AugCreateEvents.count

$AugDeleteEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13003;StartTime=$AugStartDate;EndTime=$AugEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumAugDeleteEvents = $AugDeleteEvents.count

 

# September 2015

$SepCreateEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13002;StartTime=$SepStartDate;EndTime=$SepEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumSepCreateEvents = $SepCreateEvents.count

$SepDeleteEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13003;StartTime=$SepStartDate;EndTime=$SepEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumSepDeleteEvents = $SepDeleteEvents.count

 

# October 2015

$OctCreateEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13002;StartTime=$OctStartDate;EndTime=$OctEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumOctCreateEvents = $OctCreateEvents.count

$OctDeleteEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13003;StartTime=$OctStartDate;EndTime=$OctEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumOctDeleteEvents = $OctDeleteEvents.count

 

# November 2015

$NovCreateEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13002;StartTime=$NovStartDate;EndTime=$NovEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumNovCreateEvents = $NovCreateEvents.count

$NovDeleteEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13003;StartTime=$NovStartDate;EndTime=$NovEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumNovDeleteEvents = $NovDeleteEvents.count

 

# December 2015

$DecCreateEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13002;StartTime=$DecStartDate;EndTime=$DecEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumDecCreateEvents = $DecCreateEvents.count

$DecDeleteEvents = Invoke-Command -Session $MySession -ScriptBlock {Get-WinEvent –FilterHashTable @{LogName=”Microsoft-Windows-Hyper-V-VMMS-Admin”;ID=13003;StartTime=$DecStartDate;EndTime=$DecEndDate} -ErrorAction ‘SilentlyContinue’}

$Global:NumDecDeleteEvents = $DecDeleteEvents.count

 

# Monthly Output

 Write-Host ” “

Write-Host “Server: ” -NoNewLine; Write-Host $Server

 

Write-Host “January Create Events: ” -NoNewLine; Write-Host $NumJanCreateEvents

Write-Host “January Delete Events: ” -NoNewLine; Write-Host $NumJanDeleteEvents

 

Write-Host “February Create Events: ” -NoNewLine; Write-Host $NumFebCreateEvents

Write-Host “February Delete Events: ” -NoNewLine; Write-Host $NumFebDeleteEvents

 

Write-Host “March Create Events: ” -NoNewLine; Write-Host $NumMarCreateEvents

Write-Host “March Delete Events: ” -NoNewLine; Write-Host $NumMarDeleteEvents

 

Write-Host “April Create Events: ” -NoNewLine; Write-Host $NumAprCreateEvents

Write-Host “April Delete Events: ” -NoNewLine; Write-Host $NumAprDeleteEvents

 

Write-Host “May Create Events: ” -NoNewLine; Write-Host $NumMayCreateEvents

Write-Host “May Delete Events: ” -NoNewLine; Write-Host $NumMayDeleteEvents

 

Write-Host “June Create Events: ” -NoNewLine; Write-Host $NumJunCreateEvents

Write-Host “June Delete Events: ” -NoNewLine; Write-Host $NumJunDeleteEvents

 

Write-Host “July Create Events: ” -NoNewLine; Write-Host $NumJulCreateEvents

Write-Host “July Delete Events: ” -NoNewLine; Write-Host $NumJulDeleteEvents

 

Write-Host “August Create Events: ” -NoNewLine; Write-Host $NumAugCreateEvents

Write-Host “August Delete Events: ” -NoNewLine; Write-Host $NumAugDeleteEvents

 

Write-Host “September Create Events: ” -NoNewLine; Write-Host $NumSepCreateEvents

Write-Host “September Delete Events: ” -NoNewLine; Write-Host $NumSepDeleteEvents

 

Write-Host “October Create Events: ” -NoNewLine; Write-Host $NumOctCreateEvents

Write-Host “October Delete Events: ” -NoNewLine; Write-Host $NumOctDeleteEvents

 

Write-Host “November Create Events: ” -NoNewLine; Write-Host $NumNovCreateEvents

Write-Host “November Delete Events: ” -NoNewLine; Write-Host $NumNovDeleteEvents

 

Write-Host “December Create Events: ” -NoNewLine; Write-Host $NumDecCreateEvents

Write-Host “December Delete Events: ” -NoNewLine; Write-Host $NumDecDeleteEvents

 

Write-Host ” “

}

 

#Script Body

 

#Initialize Variables

$TotalJanCreateEvents = ‘0’

$TotalJanDeleteEvents = ‘0’

$TotalFebCreateEvents = ‘0’

$TotalFebDeleteEvents = ‘0’

$TotalMarCreateEvents = ‘0’

$TotalMarDeleteEvents = ‘0’

$TotalAprCreateEvents = ‘0’

$TotalAprDeleteEvents = ‘0’

$TotalMayCreateEvents = ‘0’

$TotalMayDeleteEvents = ‘0’

$TotalJunCreateEvents = ‘0’

$TotalJunDeleteEvents = ‘0’

$TotalJulCreateEvents = ‘0’

$TotalJulDeleteEvents = ‘0’

$TotalAugCreateEvents = ‘0’

$TotalAugDeleteEvents = ‘0’

$TotalSepCreateEvents = ‘0’

$TotalSepDeleteEvents = ‘0’

$TotalOctCreateEvents = ‘0’

$TotalOctDeleteEvents = ‘0’

$TotalNovCreateEvents = ‘0’

$TotalNovDeleteEvents = ‘0’

$TotalDecCreateEvents = ‘0’

$TotalDecDeleteEvents = ‘0’

 

$Servers = @(“Hyper-V-1”, “Hyper-V-2”, “Hyper-V-3”, “Hyper-V-4”, “Prod1”, “Prod2”)

                ForEach ($Server in $Servers) {

 

                                $ServerName = $Server

                                Get-MyData $ServerName

                                $TotalJanCreateEvents = [int]$TotalJanCreateEvents + [int]$NumJanCreateEvents

                                $TotalJanDeleteEvents = [int]$TotalJanDeleteEvents + [int]$NumJanDeleteEvents

                                $TotalFebCreateEvents = [int]$TotalFebCreateEvents + [int]$NumFebCreateEvents

                                $TotalFebDeleteEvents = [int]$TotalFebDeleteEvents + [int]$NumFebDeleteEvents

                                $TotalMarCreateEvents = [int]$TotalMarCreateEvents + [int]$NumMarCreateEvents

                                $TotalMarDeleteEvents = [int]$TotalMarDeleteEvents + [int]$NumMarDeleteEvents

                                $TotalAprCreateEvents = [int]$TotalAprCreateEvents + [int]$NumAprCreateEvents

                                $TotalAprDeleteEvents = [int]$TotalAprDeleteEvents + [int]$NumAprDeleteEvents

                                $TotalMayCreateEvents = [int]$TotalMayCreateEvents + [int]$NumMayCreateEvents

                                $TotalMayDeleteEvents = [int]$TotalMayDeleteEvents + [int]$NumMayDeleteEvents

                                $TotalJunCreateEvents = [int]$TotalJunCreateEvents + [int]$NumJunCreateEvents

                                $TotalJunDeleteEvents = [int]$TotalJunDeleteEvents + [int]$NumJunDeleteEvents

                                $TotalJulCreateEvents = [int]$TotalJulCreateEvents + [int]$NumJulCreateEvents

                                $TotalJulDeleteEvents = [int]$TotalJulDeleteEvents + [int]$NumJulDeleteEvents

                                $TotalAugCreateEvents = [int]$TotalAugCreateEvents + [int]$NumAugCreateEvents

                                $TotalAugDeleteEvents = [int]$TotalAugDeleteEvents + [int]$NumAugDeleteEvents

                                $TotalSepCreateEvents = [int]$TotalSepCreateEvents + [int]$NumSepCreateEvents

                                $TotalSepDeleteEvents = [int]$TotalSepDeleteEvents + [int]$NumSepDeleteEvents

                                $TotalOctCreateEvents = [int]$TotalOctCreateEvents + [int]$NumOctCreateEvents

                                $TotalOctDeleteEvents = [int]$TotalOctDeleteEvents + [int]$NumOctDeleteEvents

                                $TotalNovCreateEvents = [int]$TotalNovCreateEvents + [int]$NumNovCreateEvents

                                $TotalNovDeleteEvents = [int]$TotalNovDeleteEvents + [int]$NumNovDeleteEvents

                                $TotalDecCreateEvents = [int]$TotalDecCreateEvents + [int]$NumDecCreateEvents

                                $TotalDecDeleteEvents = [int]$TotalDecDeleteEvents + [int]$NumDecDeleteEvents

                                }

 

Write-Host “Total January Create Events: ” -NoNewLine; Write-Host $TotalJanCreateEvents

Write-Host “Total January Delete Events: ” -NoNewLine; Write-Host $TotalJanDeleteEvents

Write-Host “Total February Create Events: ” -NoNewLine; Write-Host $TotalFebCreateEvents

Write-Host “Total February Delete Events: ” -NoNewLine; Write-Host $TotalFebDeleteEvents

Write-Host “Total March Create Events: ” -NoNewLine; Write-Host $TotalMarCreateEvents

Write-Host “Total March Delete Events: ” -NoNewLine; Write-Host $TotalMarDeleteEvents

Write-Host “Total April Create Events: ” -NoNewLine; Write-Host $TotalAprCreateEvents

Write-Host “Total April Delete Events: ” -NoNewLine; Write-Host $TotalAprDeleteEvents

Write-Host “Total May Create Events: ” -NoNewLine; Write-Host $TotalMayCreateEvents

Write-Host “Total May Delete Events: ” -NoNewLine; Write-Host $TotalMayDeleteEvents

Write-Host “Total June Create Events: ” -NoNewLine; Write-Host $TotalJunCreateEvents

Write-Host “Total June Delete Events: ” -NoNewLine; Write-Host $TotalJunDeleteEvents

Write-Host “Total July Create Events: ” -NoNewLine; Write-Host $TotalJulCreateEvents

Write-Host “Total July Delete Events: ” -NoNewLine; Write-Host $TotalJulDeleteEvents

Write-Host “Total August Create Events: ” -NoNewLine; Write-Host $TotalAugCreateEvents

Write-Host “Total August Delete Events: ” -NoNewLine; Write-Host $TotalAugDeleteEvents

Write-Host “Total September Create Events: ” -NoNewLine; Write-Host $TotalSepCreateEvents

Write-Host “Total September Delete Events: ” -NoNewLine; Write-Host $TotalSepDeleteEvents

Write-Host “Total October Create Events: ” -NoNewLine; Write-Host $TotalOctCreateEvents

Write-Host “Total October Delete Events: ” -NoNewLine; Write-Host $TotalOctDeleteEvents

Write-Host “Total November Create Events: ” -NoNewLine; Write-Host $TotalNovCreateEvents

Write-Host “Total November Delete Events: ” -NoNewLine; Write-Host $TotalNovDeleteEvents

Write-Host “Total December Create Events: ” -NoNewLine; Write-Host $TotalDecCreateEvents

Write-Host “Total December Delete Events: ” -NoNewLine; Write-Host $TotalDecDeleteEvents

You can see the script’s partial output in Figure A.

Image
Figure A: This is the output from my script.

As you can see, the script works pretty well, but there are a few things that we could potentially do to make the script even better. One possible option would be to write the script’s output to a file, which would make for easier viewing, and long term retention of the data.

PowerShell offers lots of different options for doing this. You could use the Out-File cmdlet to create a text file. PowerShell also provides cmdlets for creating HTML and CSV files. Another option would be to use simple redirection, by appending a greater than sign, followed by a filename (two greater than signs are used to append a file rather than overwriting it).

Another thing that we could potentially do would be to modify the script to calculate dates dynamically. I’m not going to do that, because it would require some major reworking of the script, but I at least want to show you a technique that you can use if you want to try modifying the script yourself.

In PowerShell, you can retrieve the current date by using the Get-Date cmdlet. You can then find a date from the past by appending .AddDays and a negative number. For example, if you wanted to find the date from 60 days ago, you could use this command:

(Get-Date).AddDays(-60)

You can see what this command looks like in Figure B.

Image
Figure B: You can use the Get-Date command to determine dates from the past.

One more thing that comes to mind would be to import the server list from a file or from a query, as opposed to hard coding the list.  Admittedly, it would be easier to pull the server names from a list than to perform a dynamic query, because PowerShell doesn’t provide a great way for listing all of the Hyper-V hosts that an organization is using. One such function however, can be found here.

Conclusion

Now that we have a well functioning script, it’s time to dump the data into a graph. I will show to do that in the next article.

If you would like to read the other parts in this article series please go to:

About The Author

Leave a Comment

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top