9 Replies Latest reply on Jan 20, 2019 11:57 PM by LucD

    -OScustomizationspec is not working properly with New-VM cmdlet

    jatinjsk Enthusiast

      Hello,

       

      I have a template (Not Content Lib Template) and deploying VM through this with -OSCustomizationSpec Switch. However i can see the VM deployment task and could also locate the VM but somehow it is not applying -OSCustomization Spec. Any help Here?

       

      Below is the Code.

       

       

      $Template=Get-Template "SGAStemplate-WIN2012R2-20180301"
      $mySpecification = Get-OSCustomizationSpec -Name RaaS-CRSR 
      New-VM -Name VMYouCanDelete -Template $Template -ResourcePool 'sol-mgmt' -OSCustomizationSpec $mySpecification 
      

       

       

      Error:

      New-VM : 1/17/2019 10:13:37 AM  New-VM          Operation is not valid due to the

      current state of the object.

      At C:\users\Administrator\Desktop\Scripts\PowerShell\RaaS\TestCustSpec.ps1:4

      char:1

      + New-VM -Name VMYouCanDelete -Template $Template -ResourcePool 'sol-mg ...

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

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

          + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomatio

         n.ViCore.Cmdlets.Commands.NewVM

        • 1. Re: -OScustomizationspec is not working properly with New-VM cmdlet
          LucD Guru
          User ModeratorsvExpertCommunity Warriors

          Which PowerCLI version are you using?

           

          Get-Module -Name VMware* -ListAvailable

           

          And which PowerShell version

           

          $PSVersionTable

           

          • 2. Re: -OScustomizationspec is not working properly with New-VM cmdlet
            LucD Guru
            User ModeratorsCommunity WarriorsvExpert

            And did you already try to stop/start the PowerShell/PowerCLI session form where you are running the script?

            • 3. Re: -OScustomizationspec is not working properly with New-VM cmdlet
              jatinjsk Enthusiast

              ModuleType Version    Name                                ExportedCommands    

              ---------- -------    ----                                ----------------    

              Script     6.7.0.8... VMware.DeployAutomation             {Add-DeployRule, A...

              Script     6.7.0.8... VMware.ImageBuilder                 {Add-EsxSoftwareDe...

              Script     6.7.0.1... VMware.Vim                                              

              Script     11.0.0.... VMware.VimAutomation.Cis.Core       {Connect-CisServer...

              Script     11.0.0.... VMware.VimAutomation.Cloud          {Add-CIDatastore, ...

              Script     11.0.0.... VMware.VimAutomation.Common                             

              Script     11.0.0.... VMware.VimAutomation.Core           {Add-PassthroughDe...

              Binary     6.0.0.0    VMware.VimAutomation.HA             Get-DrmInfo         

              Script     7.6.0.1... VMware.VimAutomation.HorizonView    {Connect-HVServer,...

              Script     10.0.0.... VMware.VimAutomation.License        Get-LicenseDataMan...

              Binary     6.5.0.4... VMware.VimAutomation.PCloud         {Connect-PIServer,...

              Script     11.0.0.... VMware.VimAutomation.Sdk            {Get-ErrorReport, ...

              Script     11.0.0.... VMware.VimAutomation.Storage        {Add-KeyManagement...

              Script     11.0.0.... VMware.VimAutomation.Vds            {Add-VDSwitchPhysi...

              Script     10.0.0.... VMware.VimAutomation.vROps          {Connect-OMServer,...

              Script     6.5.1.7... VMware.VumAutomation                {Add-EntityBaselin...

               

               

               

               

              Name                           Value                                          

              ----                           -----                                          

              PSVersion                      5.1.14409.1018                                 

              PSEdition                      Desktop                                        

              PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                        

              BuildVersion                   10.0.14409.1018                                

              CLRVersion                     4.0.30319.42000                                

              WSManStackVersion              3.0                                            

              PSRemotingProtocolVersion      2.3                                            

              SerializationVersion           1.1.0.1                                        

              • 4. Re: -OScustomizationspec is not working properly with New-VM cmdlet
                jatinjsk Enthusiast

                Yes, I first tried with PoweShell ISE and letter tried with PowerCLI.exe

                • 5. Re: -OScustomizationspec is not working properly with New-VM cmdlet
                  LucD Guru
                  User ModeratorsvExpertCommunity Warriors

                  Did you already try with another template?

                  • 6. Re: -OScustomizationspec is not working properly with New-VM cmdlet
                    jatinjsk Enthusiast

                    Yes, After closing and restarting current PowerCLI session its not giving the error. Can you suggest on a permanent solution? Please. Should i use Remove-Variable * for the next VM to be deployed.

                    • 7. Re: -OScustomizationspec is not working properly with New-VM cmdlet
                      LucD Guru
                      Community WarriorsvExpertUser Moderators

                      That is a known issue, happened to me as well a couple of times.
                      Not sure if the problem is located with PowerShell or PowerCLI.

                       

                      But I think it is a good practice to stop/start your PowerShell/PowerCLI sessions on a regular interval.
                      Independent if you are using it from a PS prompt, the ISE, the VSC...

                      • 8. Re: -OScustomizationspec is not working properly with New-VM cmdlet
                        jatinjsk Enthusiast

                        Yes, Looks like. I have a scenario where i am providing capability to users to deploy multiple VMs concurrently (Max 5 at a time) via PowerCLI script. Not sure how this will behave. Will update the thread once i am done with the UAT. Cheers LucD Thanks for your Help.

                         

                        CC: abhishekmittal02

                        • 9. Re: -OScustomizationspec is not working properly with New-VM cmdlet
                          LucD Guru
                          vExpertCommunity WarriorsUser Moderators

                          One solution I often use, is to place the script in a separate .ps1 file.
                          Then the main script, where the user can make choices, starts a PS session (with powershell.exe) and run the script.
                          The user's choices are passed as parameters to the script.
                          That way the script itself always runs in a fresh session.