VMware Cloud Community
Nacer_Bell
Contributor
Contributor

Virtual Machine pre-deployment check script

Hi,

Need your assistance to point me to some scripts portions which may help me to build a pre-check and validation script before I deploy some new VMs in my VMware environment. For your information I have no DRS, or HA set in my environment, let say it’s pretty static.     

Usually I receive a xls file with the list of VMs to deploy which contain the ESXi hostname,  Storage name (local or LUN) vCPUs, vRAM, vDisks, all the required VLANs. The goal of my script is to check all required resources for the new VMs vs what I have as a capacity resources on the hosts and the SAN as well. This script should build a csv file as an output report and should contain all the results.   

Here is a sample of what we have as info in my xls file

ESXi_Host            VM_Hostname Datastore            vCPU     vRAM (GB)          vDisk #1 (GB)     vDisk #2 (GB)     vDisk #3 (GB)                vDisk #4 (GB)     vDisk #5 (GB)     vDisk #6 (GB)     vDisk #7 (GB)     vDisk #8 (GB)     Total (GB)           NIC #1 VLAN Name    NIC #2 VLAN Name

 

I may deploy multiple VMs on a single ESXi host, so I need to calculate on needed resources with what we really have on our ESXi host and on the storage side as well.

 

Thanks in advance!

0 Kudos
7 Replies
LucD
Leadership
Leadership

What do you already have as a script?
Do you have overcommitment rules in place for CPU and memory?

Are you using Thick or Thin disks?

If using Thin, what is your maximum overcommitment percentage?

Are you taking the order of VMs in the input file into account?

When the 1st VM is created, the available resources change.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Nacer_Bell
Contributor
Contributor

Hi LucD,

 

What do you already have as a script?
Honestly, I’m just starting to think about building the script from scratch and I will be glade if someone did this kind and pre-check in his environment that I can re-use for mine.

Do you have overcommitment rules in place for CPU and memory?

For memory yes, all VMs should have their allocated memory reserved

Are you using Thick or Thin disks? Thick

If using Thin, what is your maximum overcommitment percentage?

Are you taking the order of VMs in the input file into account?

No, we are receiving the order of the VMs as a spreadsheat file, not sure what you mean by account.  

When the 1st VM is created, the available resources change.

I’m not deploying any VM, just doing resources pre-check to make sure that we are covered

Hope this answers your questions

0 Kudos
LucD
Leadership
Leadership

What I mean, if you calculate the available resources, they will change if the 1st VM of the lists is deployed.
And again after the 2nd VM, and so on...

Would you take that into account?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Nacer_Bell
Contributor
Contributor

No we do not take this in a specific account, but we do run a periodic capacity report on our vmware infra. 
0 Kudos
LucD
Leadership
Leadership

You could start with something like this

Import-Csv -Path vm.csv -UseCulture |

ConvertFrom-Csv -InputObject $data -UseCulture -PipelineVariable row |

ForEach-Object -Process {

   $esx = Get-VMHost -Name $_.ESXi_Host

   $ds = Get-Datastore -Name $_.Datastore

   New-Object -TypeName PSObject -Property ([ordered]@{

   VM = $row.VM_Hostname

   VMHost = $esx.Name

   Datastore = $ds.Name

   Memory = & { if ($esx.MemoryTotalGB -gt $row.'vRAM (GB)') { 'ok' }else { 'nok' } }

   vDisk = & {

   $totalGb = ($row | Get-Member -Name "vDisk*" | % { $row."$($_.Name)" } | Measure-Object -Sum).Sum

   if ($ds.CapacityGB -gt $totalGb) { 'ok' }else { 'nok' }

   }

   Net = & {

   $pgNames = $row | Get-Member -Name "NIC*" | % { $row."$($_.Name)" } | Sort-Object -Unique

   $pg = Get-VirtualPortGroup -Name $pgNames -ErrorAction SilentlyContinue

   if ($pgNames.Count -eq $pg.Count) { 'ok' }else { 'nok' }

   }

   })

} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Nacer_Bell
Contributor
Contributor

Thanks for you help, will try from here. Appreciate your quick replies
0 Kudos
alrojasm
Contributor
Contributor

Hello Everyone and @Nacer_Bell

Please can you help with the script to get the vm.csv file from VM Info

Thanks in Advanced

0 Kudos