This powershell script helps to run VMWare virtual machine without GUI
Works and tested with VMWare Workstation 16 Player
| $vmRunCommand = "`"C:\Program Files (x86)\VMware\VMware Player\vmrun.exe`"" | |
| $ubuntuVmxPath = "`"C:\Users\<username>\Documents\Virtual Machines\ubuntu\ubuntu.vmx`"" | |
| [string[]]$choices = "&Start", "Safe S&uspend", "&Hard Suspend","Safe Hal&t", "Har&d Halt", "&Cancel" | |
| $result = $host.ui.PromptForChoice("What to do?", "What you want to do with the VM?", $choices, 5) | |
| switch($result){ | |
| 0{ | |
| $startVmCommand = $vmRunCommand | |
| $startVmCommand += " start " | |
| $startVmCommand += $ubuntuVmxPath | |
| $startVmCommand += " nogui" | |
| Write-Host $startVmCommand | |
| cmd.exe /c $startVmCommand | |
| $getIpCommand = $vmRunCommand | |
| $getIpCommand += " getGuestIPAddress " | |
| $getIpCommand += $ubuntuVmxPath | |
| $getIpCommand += " -wait" | |
| Write-Host $getIpCommand | |
| $ubuIp = cmd.exe /c $getIpCommand | |
| $startRdpCommmand = "mstsc /v " | |
| $startRdpCommmand += $ubuIp | |
| $startRdpCommmand += ":3389" | |
| Write-Host $startRdpCommmand | |
| cmd.exe /c $startRdpCommmand | |
| } | |
| 1{ | |
| $stopVmCommand = $vmRunCommand | |
| $stopVmCommand += " suspend " | |
| $stopVmCommand += $ubuntuVmxPath | |
| $stopVmCommand += " soft" | |
| Write-Host $stopVmCommand | |
| cmd.exe /c $stopVmCommand | |
| } | |
| 2{ | |
| $stopVmCommand = $vmRunCommand | |
| $stopVmCommand += " suspend " | |
| $stopVmCommand += $ubuntuVmxPath | |
| $stopVmCommand += " hard" | |
| Write-Host $stopVmCommand | |
| cmd.exe /c $stopVmCommand | |
| } | |
| 3{ | |
| $stopVmCommand = $vmRunCommand | |
| $stopVmCommand += " stop " | |
| $stopVmCommand += $ubuntuVmxPath | |
| $stopVmCommand += " soft" | |
| Write-Host $stopVmCommand | |
| cmd.exe /c $stopVmCommand | |
| } | |
| 4{ | |
| $stopVmCommand = $vmRunCommand | |
| $stopVmCommand += " stop " | |
| $stopVmCommand += $ubuntuVmxPath | |
| $stopVmCommand += " hard" | |
| Write-Host $stopVmCommand | |
| cmd.exe /c $stopVmCommand | |
| } | |
| 5{ | |
| Write-Output "Cancelled" | |
| } | |
| } | |
| exit | |