VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

issue with the function

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]:

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

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

Please help in changing that.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thank you very much LucD.

That worked perfect  Smiley Happy

0 Kudos