haripadmam
Hot Shot
Hot Shot

Automate VM power off

Hi Folks, not sure if this is right location.

Currently we are doing bulk power operations of VMs like below. Is there anyway, if we execute this, first it will just pop up/list all VMs from the file to confirm operation before executing it than one by one? I just don't want to skip confirmation with Confirm:$false; neither do it one at a time.

Shutdown-VMGuest -VM (Get-Content <textfile>

Thanks for any help!

Cheers,

Hari

0 Kudos
3 Replies
scott28tt
VMware Employee
VMware Employee

@haripadmam 

Moderator: Moved to PowerCLI Discussions

0 Kudos
LucD
Leadership
Leadership

You mean something like this?

$vmNames = Get-Content -Path <textfile>
$vms = Get-VM -Name $vmNames
Format-Wide -InputObject $vms -Property Name -Column 4
$answer = Read-Host -Prompt "Is it ok to shutdown these VMs? (y/n)"
if($answer -eq 'y'){
    Shutdown-VMGuest -VM $vms -Confirm:$false
}


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

haripadmam
Hot Shot
Hot Shot

Hi LucD, hope you doing good!

Yeah, I believe it should do, will test it today.

Cheers,

Hari

0 Kudos