View Only
  • 1.  PowerCLI - Deploy VM-templates from CSV

    Posted Feb 19, 2016 12:37 PM

    Having issues with a script.  I feel I'm close but I'm still missing something...  I'm not sure if the issue lies within PowerCLI or my lacking PowerShell knowledge. 

    My PowerCLI 6 script seems to work but only at a low level.  It creates the VMs but doesn't seem to assign the IP or hostname to the newly created VM.  So, when it's time to apply the Customization Specification, it either times out or just doesn't fully apply; I'm not sure which as no errors get spit back at me.  It creates the VM with the correct name & changes the port-group on which the NIC will sit but that seems to be about it.  I've manually tested the Customization Specification and template that are being used in this script and it looks fine after a manual walk-through.  For some reason, some the info from the CSV is not being used correctly or at all.

    The script I have is pretty long and I didn't want to muck up the page with it so I dumped it on PasteBin; hope that's ok...



  • 2.  RE: PowerCLI - Deploy VM-templates from CSV

    Posted Feb 19, 2016 12:50 PM

    The Get-FolderByPath function was updated yesterday, so you better get the new version.

    Although I don't think this has any effect on your script.

    I would use the parameter -IpMode:UseStaticIP  as -IpMode UseStaticIP .

    Not sure if it works correctly the way you did it.

    The OSCustomization is applied at the first start of the VM, so I'm not sure if removing it before you start the VM could be causing any issues.

    Have a look at KB1026317, it contains some techniques to troubleshoot a failing OSCustomization.

    The log  it leaves behind could perhaps give some pointers on what might be going wrong.

  • 3.  RE: PowerCLI - Deploy VM-templates from CSV

    Posted Feb 19, 2016 01:00 PM

    Understood; I'll grab your latest function.  Nice work on that one by the way...

    Interesting points regarding the start of the VM in relationship to the deletion of the temporary custom spec; I had not considered that.  (Side note: I wish the -Type NonPersistent switch worked with New-OSCustomizationSpec...)  I'll make the changes and report back.

  • 4.  RE: PowerCLI - Deploy VM-templates from CSV

    Posted Feb 19, 2016 02:41 PM

    Still no joy...

    By the way, the -IpMode:UseStaticIP works - as is - in two other script I have.  One deploys VMs by cloning another powered-off VM and the other deploys them via a template.  Both prompt the user to enter IP info as the script progresses.  Both scripts were the precursors to the one I'm working on now...  Anyway, I made your recommended change to -IpMode UseStaticIP but that didn't make a difference.

    I constantly watch the output while the scripts run - just to catch any errors.  I managed to capture the output and, again, it all looks like it's creating a VM with all the correct info.  Before my original post, I even filled the CSV with some bogus data - trying to trick the script into a failure - thinking the script just wasn't pulling in the correct data.  However, that didn't seem to make a difference; it seems the data is being pulled in correctly.

    Looking at that KB article let nowhere.  None of the paths seem to apply to my Windows 2012 server.  I poked around the %Windir%\Temp directory but anything looking to be VMware-related, was empty.

    I also commented out the Remove-OSCustomizationSpec bit to test the deletion and powering-on theory.  Again, there was no change in the final product. 

    Also note that the Remove-OSCustomizationSpec in the other two scripts is done before the Start-VM - again, with successful results.  So, I'm not sure changing that order makes much of a difference.  At least not in my case...

  • 5.  RE: PowerCLI - Deploy VM-templates from CSV

    Posted Feb 19, 2016 04:48 PM

    If %Windir%\Temp is empty, that seems to indicate that the OS Customization didn't run at all.

    Is there anything in the vmware.log (in the VM's folder) that could help ?

  • 6.  RE: PowerCLI - Deploy VM-templates from CSV

    Posted Feb 19, 2016 06:17 PM

    Well, that's a busy log....  2300 lines up on Pastebin for everyone's viewing pleasure.  It was located inside the VM's folder on the cluster's storage.  I see a lot of Remote connection failure messages at the bottom of said file.


  • 7.  RE: PowerCLI - Deploy VM-templates from CSV
    Best Answer

    Posted Feb 19, 2016 06:50 PM

    Found my issue.  Everything was fine except for the New-VM line; it had the wrong variable for the -OSCustomizationSpec switch.  Feeling a bit foolish but it's been a long week. 

    Bad line:

    New-VM -Name $GuestVM -Template $Template -Location $VMFolder -OSCustomizationSpec $CustSpec -ResourcePool $Cluster -Datastore $Datastore

    Good line:

    New-VM -Name $GuestVM -Template $Template -Location $VMFolder -OSCustomizationSpec $TempCustSpec -ResourcePool $Cluster -Datastore $Datastore

  • 8.  RE: PowerCLI - Deploy VM-templates from CSV

    Posted Aug 15, 2017 07:23 PM

    First of all, thanks for this and Sorry for waking up an old thread.

    Can I ask why run "Remove-OSCustomizationSpec $GuestVM -Confirm:$False"?

    I missed the point there.

  • 9.  RE: PowerCLI - Deploy VM-templates from CSV

    Posted Aug 15, 2017 08:08 PM

    The user creates a persistent OSCustomizatonSpec, and he cleans it up after he's done with it.

    He could have created a nonpersistent one, that would have been removed automatically when the PS session was closed.

  • 10.  RE: PowerCLI - Deploy VM-templates from CSV

    Posted Mar 06, 2018 09:27 AM

    Hi All,

    Thank you very much for this script, it works as it should. I have customized it a little bit  adding value for memory and CPU/Core values. There is one thing that we use very often during deploying VM from templates, which is adding additional hard drive disks that are located on same DS as deployed VM. Disks are always added in Thick - Lazy Zeroed format.

    Would it be possible to add value in CSV like DiskNum and DiskSize that would automatically add vdisks to VM after deploying from template?

    Let's say DiskNum - value 3, DiskSize 5-10-15 (add three disks with size 5GB, 10GB and 15GB)?

    If that's possible, could you just give me the idea how to even start it? Should I use -DiskGB during New VM creation?