Hi, i want to create a script for my hyper-v virtual machine.
This scritp start vm if the vm is off.I know the command to do that, but the syntax is my problem.
In this scritp i want to select 1 virtual machine and if it is off, my script just start it, but if my vm is on, the script write me “the vm is running”.
At this time i write a script but the syntax is not correct, please help me!

I think to use this command:

if (Get-VM | Format-Table name, state -eq running) {write-host -foregroundcolor red "VM running}
else(start-vm -name "name")
3 Spice ups
if (Get-VM | Format-Table name, state -eq running) {write-host -foregroundcolor red "VM running"}
else(start-vm -name "name")

You’re missing a ’ " ’ in the line “VM running” ?

1 Spice up

This should be better:

if (Get-VM | Format-Table name, state -eq running)
{
    write-host -foregroundcolor red "VM running"
}
else 
{
    start-vm -name "name"
}
2 Spice ups

sorry but you scritp not run.
i solved!!!
Thanks to all.

Well, good for you.

But you could post your solution in case someone else stumbles upon this thread.

2 Spice ups