# 描述:用于批量启动VirtualBox虚拟机的PowerShell脚本 Write-Host "========================================" -ForegroundColor Cyan Write-Host " VirtualBox 虚拟机批量启动工具" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan Write-Host "" # 1. 配置区域:请根据您的实际情况修改以下变量 # 将虚拟机名称放在下面的数组中,可以是一个或多个 $VM_Names = @("CentOS", "fnOS") # 设置启动模式: 'gui' 或 'headless' $StartType = 'gui' # 如果VBoxManage不在系统PATH中,请指定完整路径(通常不需要) $VBoxManagePath = "C:\Users\NAS\Programs\VirtualBox\VBoxManage.exe" # 默认使用系统路径中的命令 # 2. 获取当前所有虚拟机列表(可选,用于确认) Write-Host "正在获取虚拟机列表..." -ForegroundColor Yellow $AllVMs = & $VBoxManagePath list vms Write-Host "当前已注册的虚拟机:" -ForegroundColor Green $AllVMs | ForEach-Object { Write-Host " $_" } Write-Host "" Write-Host "开始启动虚拟机 [$StartType 模式]..." -ForegroundColor Yellow # 3. 循环启动虚拟机 foreach ($VM in $VM_Names) { Write-Host "正在启动虚拟机: $VM" -ForegroundColor White try { # 执行启动命令 & $VBoxManagePath startvm $VM --type $StartType Write-Host "[成功] `"$VM`" 已启动." -ForegroundColor Green } catch { Write-Host "[错误] 启动 `"$VM`" 时发生问题: $_" -ForegroundColor Red } Write-Host "----------------------------------------" -ForegroundColor DarkGray } Write-Host "批量启动操作已完成!" -ForegroundColor Cyan Write-Host "使用 'VBoxManage list runningvms' 命令查看正在运行的虚拟机。" -ForegroundColor Yellow # 可选:自动列出当前正在运行的虚拟机 Write-Host "" Write-Host "当前正在运行的虚拟机:" -ForegroundColor Green & $VBoxManagePath list runningvms pause