VMware Cloud Community
lorried82
Enthusiast
Enthusiast
Jump to solution

Disk format from vm build via template

I built a VM exactly how I wanted it - including the disks to be all provisioned as thick lazy zero. I then converted the VM to a template.

I have a powercli script that then builds VM from this template, however it is not formatting the disk the same - it is making them all thin. Is there something I need to include in the powercli script to change the format?

any help/input/comments appreciated. The script that I use is below

$data = import-csv C:\input_data.csv

#Pass in vaiables from imput file that include vmname,template,cluster,spec,notes,vlan,tag,datastore

foreach ($var in $data)

{New-VM -Name $var.vmname -Template $var.template -ResourcePool $var.cluster -OSCustomizationSpec $var.spec -Description $var.notes -datastore $var.datastore

#Set the vlan for the vm

Get-VM $var.vmname | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $var.vlan -Confirm:$False

#Tag the vm accordingly for Avamar to back it up

Get-VM $var.vmname | New-TagAssignment -Tag $var.tag

}

Start-VM -VM $var.vmname

#disconnet from the server

disconnect-viserver * -Confirm:$False

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Something like this

Get-DatastoreCluster -Name MyDSC | Get-Datastore | Get-Random


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

View solution in original post

Reply
0 Kudos
12 Replies
LucD
Leadership
Leadership
Jump to solution

Did you already try adding the DiskStorageFormat parameter on the New-VM cmdlet?


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

Reply
0 Kudos
lorried82
Enthusiast
Enthusiast
Jump to solution

Hi LucD - I was not sure how to get that added. So I can have it format it as thick instead of doing something like inflate?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, all the options are listed on the Help page: Thin, Thick or EagerZeroedThick


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

Reply
0 Kudos
lorried82
Enthusiast
Enthusiast
Jump to solution

so the issue with that is since I want to just use a datastore cluster - when I add -DiskFromatType it errors out that it is missing the required property datastore

So basically I added below - is there a way I can achieve this?

{New-VM -Name $var.vmname -Template $var.template -ResourcePool $var.cluster -OSCustomizationSpec $var.spec -Description $var.notes -datastore $var.datastore -DiskStorageFormat 'thick'

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Not with the cmdlet I'm afraid.

You could take a random datastore from the datastorecluster, and use that one.

The alternative would be to use the API method directly.


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

Reply
0 Kudos
lorried82
Enthusiast
Enthusiast
Jump to solution

Ok thanks LucD. Is there a way to randomly pick a datastore?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Something like this

Get-DatastoreCluster -Name MyDSC | Get-Datastore | Get-Random


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

Reply
0 Kudos
lorried82
Enthusiast
Enthusiast
Jump to solution

Thanks so much LucD - this works great.

So it will only provision to a datastore that has enough space - right? I see all my disks are provisioned to the same datastore.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, you would still need to check if the random datastore has sufficient free space to host the VM.

And yes, all VMDK will be placed on the same datastore.

If you want to use different datastores for the different VMDK, you will have to go for the API method.

Afiak, that is not possible with the cmdlet.


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

Reply
0 Kudos
lorried82
Enthusiast
Enthusiast
Jump to solution

ok thank you. So is there an easy way to know if there is enough space or what happens if a disk is chosen without enough space?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The objects returned by Get-Datastore have a property named FreeSpaceGB.

You can use that to check if there is sufficient space available.


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

Reply
0 Kudos
lorried82
Enthusiast
Enthusiast
Jump to solution

thanks so much!

Reply
0 Kudos