4 Replies Latest reply on Dec 9, 2019 11:40 PM by ganapa2000

    issue with the function

    ganapa2000 Hot Shot

      Hi,

       

      I am unable to execute the attached script as I am getting the below error

       

      Please help.

       

      Output :

      PS D:\> .\Clone_VM.ps1                                                                                                

      cmdlet Clone_VM.ps1 at command pipeline position 1

      Supply values for the following parameters:

      vmList[0]:

        • 1. Re: issue with the function
          LucD Guru
          User ModeratorsvExpertCommunity Warriors

          In that script the parameter vmList is defined as mandatory.

          So you will have to provide that parameter

           

          $vms = Get-VM -Name vm1,vm2,vm3

          .\Clone_VM.ps1 -vmList $vms

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: issue with the function
            ganapa2000 Hot Shot

            LucD,

             

            I would like to mention the parameters inside the script rather than mentioning outside while running.

             

            Please help in changing that.

            • 3. Re: issue with the function
              LucD Guru
              vExpertUser ModeratorsCommunity Warriors

              You would need to take away the 'mandatory' part of the parameter definition.
              And assign a value inside the script.

               

              The first couple of lines could look like this

               

              [CmdletBinding()]

              param(

                 # VMs to monitor for OS customization completion

                 [VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine[]] $vmList = (Get-VM -Name vm1,vm2,vm3),

                 # timeout in seconds to wait

                 [int] $timeoutSeconds = 600

              )

               

              But to be honest, if you don't want to use parameters when calling the script, you can just as well leave out the complete Param part.
              And just do the following at the beginning of the script.

               

              $vmList = Get-VM -Name vm1,vm2,vm3

              $timeoutSeconds = 600

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: issue with the function
                ganapa2000 Hot Shot

                Thank you very much LucD.

                 

                That worked perfect