VMware Cloud Community
vmk2014
Expert
Expert
Jump to solution

Shutdown VM & poweron will work or not

Hi Everyone,

Recently, i tested the script from LucD, but not sure if it will work on schedule time or not tomorrow because of recent error

Why every time its throwing an error for Name parameter.

pastedImage_5.png

$vmNames = Get-Content -Path C:\Temp\vmnames.txt

$vms = Get-VM -Name $vmNames |

    where{$_.PowerState -eq 'PoweredOn'}

    Shutdown-VMGuest -VM $vms -Confirm:$false

while((Get-VM -Name $vmNames).PowerState -contains 'PoweredOn'){

    sleep 5

}

$vms | Select Name |  Export-Csv C:\Temp\vm-powered-off.csv -NoTypeInformation -UseCulture

**************************************************************************

For Power on

$vmNames = Import-Csv -Path C:\Temp\vm-powered-off.csv  -UseCulture

Get-VM -Name $vmNames.Name |

Start-VM -Confirm:$false

Tags (1)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Isn't that the same problem we just had, where there seems to be a blank line in the .txt file.

Try replacing the line with

$vmNames = Get-Content -Path C:\Temp\vmnames.txt | where{$_}


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

View solution in original post

0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

Isn't that the same problem we just had, where there seems to be a blank line in the .txt file.

Try replacing the line with

$vmNames = Get-Content -Path C:\Temp\vmnames.txt | where{$_}


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

0 Kudos
a_p_
Leadership
Leadership
Jump to solution

Please try the solution LucD​ gave you for your other question (Re: Can we pull VMware tools version and VM's HW version for specific lists of VMs ?), i.e. skiping any blank lines.

André

vmk2014
Expert
Expert
Jump to solution

Thank you Will replace as you suggestion. I was worried because first, we are doing non-prod followed by Prod.

0 Kudos
vmk2014
Expert
Expert
Jump to solution

Sorry its failing to poweron

pastedImage_0.png

$vmNames = Import-Csv -Path C:\Temp\vm-powered-off.csv  -UseCulture

Get-VM -Name $vmNames.Name |

Start-VM -Confirm:$false

#############################################################################

even the 2nd also not working failing with same error

$vmNames = Get-Content -Path C:\Temp\vmliste.txt | where{$_}

Get-VM -Name $vmNames.Name |

Start-VM -Confirm:$false

0 Kudos
vmk2014
Expert
Expert
Jump to solution

LucD,

Finally below script saved me for bulk VMs power-on requirement, otherwise, it would have been manual tasks for me

foreach($vmlist in (Get-Content -Path C:\TEMP\vmliste.txt)){

$vm = Get-VM -Name $vmlist

Start-VM -VM $vm -Confirm:$false

}

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I find it hard to believe that this issue is not caused by a blank line in your .txt file (which you confirmed in a previous thread).

Also strange that one time you seem to use a .txt file, and the other you seem to use a .csv file..

The script that fixes the issue, according to you, has no provision for blank lines in the .txt file.
Something else must have changed

Very hard to pinpoint an issue when you don't share all the information Smiley Sad


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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

What I also find very strange, you retract my Correct Answer, which is your good right.
But you keep the Like you gave to another answer, that just repeated my answer.


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

0 Kudos
vmk2014
Expert
Expert
Jump to solution

Hi LucD,

My apologies, it was my mistake since there were multiple console were open and it was retracted by mistake.  Sorry once again. Smiley Happy 

thanks

vmk

0 Kudos
LucD
Leadership
Leadership
Jump to solution

No problem, I guessed as much :smileygrin:

Is everything working as planned now?


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

0 Kudos
vmk2014
Expert
Expert
Jump to solution

Thank you LucD, Everything worked on the plan. Since it was a bulk upgrade and I was worried about the downtime Window.

0 Kudos