I am writing a script to start a VM if it's not currently running. I know the commands to do that, but I got trouble with the syntax.
In this script I want to select a virtual machine and if it is off, my script just starts it, but if the VM is on, the script displays a message "The VM is running".
At this time I write a script but the syntax is not correct:
if (Get-VM | Format-Table name, state -eq running) {
Write-Host -ForegroundColor red "VM running
}
else(start-vm -name "name")