Hello,
I am attempting to write a script that will recursively go through a folder and populate an array with hard disk paths. Once the array is populated, create an appropriate number of VM's (i.e. less than 56, create a single VM, between 56 and 112, create two VM's, etc.) and attach the disks (non-persistent) appropriately. I was hoping to be able to use the New-VM command line to do this all at once, but I'm having a hard time breaking the array out to work with a single command line, and adding the disks to an existing VM has also proven to be a bit more difficult than I had expected.
Does anyone have some guidance that could point me in the right direction? Perhaps a snippet of a script that is designed to do something similar?
Thanks very much,
Mark
Some questions; how do you populate that array exactly ?
In fact which folder are you referring to ?
Perhaps it will be easier to understand if you show a dummy sample of the array.
Did you already try using the New-Harddisk cmdlet to add a harddisk to a VM ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
Here is some sample output to answer your questions:
Write-Host "Populating Disk Array..."
$disks = @(Get-ChildItem ds:\UNIDESK-MCP\UnideskLayers\OS -Recurse -include *.vmdk -Exclude *snapshot*,*-flat.vmdk,*user\* -name) #ds is a PSDrive at the root of the datastore
When I issue the New-Harddisk command, I can connect a single VMDK by using -DiskPath [DataStore] Path/$disks[$x], but I'd like to have a better way of doing this all in one line. We could have anywhere from 20 to 100 VMDK's that need to be backed up, so I can't use anything static, which makes the script more difficult. I've been able to break the array down into chunks, so the multiple VM issue should be manageable, it's just the issue of adding multiple paths from the array in one line for simplicity that remains. (at least for now)
Thanks for the help,
Mark
So if I understand your question correctly:
If that is indeed the correct interpretation then you could do something like this
$vm = Get-VM -Name MyVM
Get-ChildItem ds:\UNIDESK-MCP\UnideskLayers\OS -Recurse -include *.vmdk -Exclude *snapshot*,*-flat.vmdk,*user\* -name | %{
New-HardDisk -VM $vm -DiskPath $_.DatastoreFullPath -Persistence "IndependentNonPersistent" -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
That's a good start, the problem comes in with the number of disks VMware supports per VM. We will definitely have more than 65 disks now, which is about 9 more than you can put on one server. I'll look into how I might be able to adapt this script to fit that scenario, but if you have input, that would be appreciated.
Thanks,
Mark
How do you want to cope with the max number of harddisks on a VM ?
Assign as many as possible to VM1, and then remaining ones to VM2, VM3 and so on ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, just as you said it. 56 on the first, and then start on the second, then the third, etc.