2010-10-02 44 views
2

我已經創建了一個虛擬機。現在我正嘗試使用Powershell啓動它。我已經在互聯網上搜索了關於如何做到這一點的任何細節。這是唯一的代碼,我發現...VirtualBox + Powershell?

#---------------------- 
$vBox = New-Object -ComObject VirtualBox.VirtualBox 
$vBox | Get-Member * 

$vBox.Machines 

$vBox.CreateMachine() 
#---------------------- 

(來源:http://www.ravichaganti.com/blog/?p=1275

其實,我找不到上virtualbox.org COM對象的任何文件。我fiarly使用PowerShell proficent,我花了一些時間探索COM對象與...

$vBox | gm 

我想每一件事我能想到的,但只有收到錯誤。爲什麼不直接使用VBoxManage命令行界面 - 我的問題是我怎麼使用PowerShell

感謝

回答

7

而不是使用COM對象啓動我的虛擬機?

相關命令你的問題是:

VBoxManage createvm  --name <name> 
         [--ostype <ostype>] 
         [--register] 
         [--basefolder <path> | --settingsfile <path>] 
         [--uuid <uuid>] 

VBoxManage startvm  <uuid>|<name> 
         [--type gui|sdl|vrdp|headless] 

的VBoxManage可執行文件的安裝目錄,默認情況下將是C發現:\ Program Files文件\的Oralce \ VirtualBox的(如3.2.8版本至少)。

使用COM API,看來VirtualBox.OpenSession方法是您需要使用的方法,但我似乎無法讓PowerShell強制使用ISession變量來匹配方法簽名並調用方法。也許通過一些聰明的反思或者可以做的事情。

+0

我的經驗是,在一個PowerShell遠程會話中運行'VBoxManage'(通過調用' - Command'或'輸入 - PSSession')使用COM接口引擎蓋下與virtualbox進行交互。爲了解決這個問題,你必須設置另一個遠程登錄機制,例如SSH,以便「直接」運行VBoxManage。我很想知道我對此有錯。 – Dan1701 2016-03-28 00:34:54

3

以下鏈接包含一篇關於在PowerShell中使用VirtualBox的文章,並且包含一個包含一些漂亮的PowerShell cmdlet的方便模塊。

雖然您可以使用命令行,但該命令很長,它不是交互式的,並且您不能輕鬆解析結果(例如機器列表等)。 這隻適用於PowerShell。

鏈接中的模塊包含一個包裝對象,所以您不必擔心處置COM對象或任何東西。

這裏是鏈接: http://jdhitsolutions.com/blog/scripting/1502/managing-virtualbox-with-powershell/