NeoKumar
Enthusiast
Enthusiast

VM power on in Sequence from multiple Clusters

Need help on Script to power on VMS in sequence order from a input file, which contains VM names

could someone help

0 Kudos
11 Replies
LucD
Leadership
Leadership

What format is the input file?
Should a VM be fully started before the next one is started?
Where do the clusters come into play?
What do you already have?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
NeoKumar
Enthusiast
Enthusiast

Hi Lucd, the format can be text file or csv.

each line will contain the virtual machine name which will power on 1st and then wait for some time and then power on 2nd VM.. so on..

we have mutiple cluster in same vcenter, and the VMs are spread across. so we thought to use input file and mention VM names direclty rather than thinking of cluster.

we currently have 4 line script, which takes input file and power on vms same time.

Tags (1)
0 Kudos
LucD
Leadership
Leadership

If you just want to "wait for some time", you can insert a Start-Sleep cmdlet after each power on.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
NeoKumar
Enthusiast
Enthusiast

Tried this script,

ForEach-Object -Process {

 Import-Csv -Path .\startorder.csv -UseCulture |

$vm = Get-VM -Name $_.Name | Start-VM -Confirm:$false

 while(-not $vm.ExtensionData.Guest.GuestOperationsReady){

 Start-Sleep -Seconds 5

 $vm = Get-VM -Name $vm.Name

 }

}

This is a throwing error:

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:1 char:20
+ $vm = Get-VM -Name $_.Name | Start-VM -Confirm:$false
+ ~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

0 Kudos
LucD
Leadership
Leadership

The Import-Csv needs to be outside the loop

Import-Csv -Path .\startorder.csv -UseCulture |
ForEach-Object -Process {
    $vm = Get-VM -Name $_.Name | Start-VM -Confirm:$false
    while(-not $vm.ExtensionData.Guest.GuestOperationsReady){
       Start-Sleep -Seconds 5
         $vm = Get-VM -Name $vm.Name
     }
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
NeoKumar
Enthusiast
Enthusiast

Still same error Friend.

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:6 char:29
+ $vm = Get-VM -Name $vm.Name
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

0 Kudos
LucD
Leadership
Leadership

Do you have a blank line in your CSV?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
NeoKumar
Enthusiast
Enthusiast

I tried csv file content as: vm1,vm2.vm3

then i tried csv file content as:

vm1

vm2

vm3

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:2 char:24
+ $vm = Get-VM -Name $_.Name | Start-VM -Confirm:$false
+ ~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:5 char:29
+ $vm = Get-VM -Name $vm.Name
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:5 char:29
+ $vm = Get-VM -Name $vm.Name
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:5 char:29
+ $vm = Get-VM -Name $vm.Name
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:5 char:29
+ $vm = Get-VM -Name $vm.Name
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:5 char:29
+ $vm = Get-VM -Name $vm.Name
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:5 char:29
+ $vm = Get-VM -Name $vm.Name
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:5 char:29
+ $vm = Get-VM -Name $vm.Name
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:5 char:29
+ $vm = Get-VM -Name $vm.Name
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:5 char:29
+ $vm = Get-VM -Name $vm.Name
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:5 char:29
+ $vm = Get-VM -Name $vm.Name
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:5 char:29
+ $vm = Get-VM -Name $vm.Name
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:5 char:29
+ $vm = Get-VM -Name $vm.Name
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:5 char:29
+ $vm = Get-VM -Name $vm.Name
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:5 char:29
+ $vm = Get-VM -Name $vm.Name
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:5 char:29
+ $vm = Get-VM -Name $vm.Name
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:5 char:29
+ $vm = Get-VM -Name $vm.Name
+ ~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

0 Kudos
NeoKumar
Enthusiast
Enthusiast

No LucD, file contains: vm1,vm2,vm3

and

also tired file content as:

vm1

vm2

vm3

still error.

0 Kudos
LucD
Leadership
Leadership

You need a column name and one VM per line

Name
vm1
vm2
vm3

 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

NeoKumar
Enthusiast
Enthusiast

worked! the smallest error, sometimes costs a lot.. only an expert like you can pinpoint it! thanks Lucd 🙂 

0 Kudos