Browse Source

Uploaded VM Always On files

Powershell script and Windows Scheduled Task to start VirtualBox VM(s) on system boot and verify that they are running every 5 minutes
i12bretro 4 years ago
parent
commit
da04b76fc7
2 changed files with 25 additions and 0 deletions
  1. 25 0
      _Downloads/VM_Always_On.ps1
  2. BIN
      _Downloads/VMs Always On.xml

+ 25 - 0
_Downloads/VM_Always_On.ps1

@@ -0,0 +1,25 @@
+# VIRTUALBOX INSTALLATION PATH; CHANGE IF NOT INSTALLED IN THE DEFAULT LOCATION
+$vboxPath = ($Env:Programfiles +'\Oracle\VirtualBox\')
+# CASE SENSITIVE NAME OR UUID OF VMS TO KEEP RUNNING
+# ex @('Vm1','VM2','vm3','cfeb596c-3e21-1eec-a015-a496559a3d11')
+$alwaysRunningVMs = @('')
+
+# GET A LIST OF CURRENTLY RUNNING VMS
+$runningVMs = Invoke-Expression ('& "'+ $vboxPath +'vboxmanage.exe" list runningvms')
+Write-Host 'VMs Currently Running' -ForegroundColor 'Green'
+Write-Host '-----------------------------------------------' -ForegroundColor 'Green'
+Write-Host $runningVMs -ForegroundColor 'Green'
+Write-Host '-----------------------------------------------' -ForegroundColor 'Green'
+Write-Host
+
+# LOOP THROUGH $alwaysRunningVMs AND COMPARE TO RUNNING VMS
+for($i=0; $i -lt $alwaysRunningVMs.length; $i++){
+	Write-Host ('*** Checking "'+ $alwaysRunningVMs[$i] +'"')
+	if($runningVMs -like ('*"'+ $alwaysRunningVMs[$i] +'"*') -or $runningVMs -like ('*{'+ $alwaysRunningVMs[$i] +'}*')){
+		Write-Host ("`t" + $alwaysRunningVMs[$i] +' is running')
+	} else {
+		Write-Host ("`tStarting "+ $alwaysRunningVMs[$i])
+		Write-Host -NoNewline "`t"
+		Invoke-Expression ('& "'+ $vboxPath +'vboxmanage.exe" startvm '+ $alwaysRunningVMs[$i] +' --type headless') 
+	}
+}

BIN
_Downloads/VMs Always On.xml