Need help on Script to power on VMS in sequence order from a input file, which contains VM names
could someone help
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
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.
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
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
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
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
Do you have a blank line in your CSV?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
No LucD, file contains: vm1,vm2,vm3
and
also tired file content as:
vm1
vm2
vm3
still error.
You need a column name and one VM per line
Name
vm1
vm2
vm3
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
worked! the smallest error, sometimes costs a lot.. only an expert like you can pinpoint it! thanks Lucd 🙂