8 Replies Latest reply on Aug 6, 2018 4:21 AM by LucD

    Deploy VM from template fails

    alfwro Lurker

      I'm trying to automate vm from template deployment, here is my script:


      param (







      Get-OSCustomizationSpec -name "W7_cust" | New-OSCustomizationSpec -name tempcust -type NonPersistent


      Get-OSCustomizationSpec -name tempcust | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $ipAddress -SubnetMask -DefaultGateway -dns


      $osCust = Get-OSCustomizationSpec -Name tempcust


      new-vm -name $vmName -ResourcePool Test -Template template_name -Datastore stor01 -Folder "Folder" -OSCustomizationSpec $osCust



      I know the script is fine because I can run it line by line and it executes OK however when I run it as above in a form of a script it fails with this error:


      new-vm : 06/08/2018 10:42:20    New-VM          Operation is not valid due to the current state of the object.

      At G:\deploy-training-VM.ps1:14 char:1

      + new-vm -name $vmName -ResourcePool Test -Template template_name  ...

      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

          + CategoryInfo          : NotSpecified: (:) [New-VM], VimException

          + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM


      Why does it fail? How do I get it working?