Skip to content

Instantly share code, notes, and snippets.

@pishangujeniya
Created July 2, 2022 08:14
Show Gist options
  • Save pishangujeniya/05cc1949c1085ca57103fb9f518c890f to your computer and use it in GitHub Desktop.
Save pishangujeniya/05cc1949c1085ca57103fb9f518c890f to your computer and use it in GitHub Desktop.
This powershell script helps to run VMWare virtual machine without GUI

VMWare No GUI Headless

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment