Can someone tell me why the following won't work. "stop-vmguest" not able to see the value of $vm . Keeps saying it's null.
I can run the command manually with no problem "stop-vmguest -vm host_01 -confirm:$true" .
Thanks,
wbrunc
Contents of C:\temp\test1.csv
"host_01"
"host_02"
-----------------------------
#start of script
$TEST_vms_to_shut_snap_on=import-csv c:\temp\test1.csv
foreach ($vm in $TEST_vms_to_shut_snap_on)
{
stop-vmguest -vm $vm -confirm:$true
sleep 60
}
Give a try with
Stop-VMGuest -VM (Get-VM $vm) -Confirm:$true
That didn't work.
Ok.
Guess I figured out the problem.
Feed the input to csv file like below (firstline is a title)
VMname
server1
server2
and modify the script as below
Stop-VMGuest -VM (Get-VM $vm.VMname) -Confirm:$true
Alternatively you can just input the VM names in a text file
Contents on C:\temp\test1.txt
server1
server2
..
and below script block should do the trick
$TEST_vms_to_shut_snap_on=Get-Content C:\temp\test1.txt
foreach ($vm in $TEST_vms_to_shut_snap_on)
{
stop-vmguest -vm $vm -confirm:$true
sleep 60
}
Prakash,
Using the txt file worked, thank you .
Bill