簡體   English   中英

使用PowerCLI Invoke-VMScript在來賓VM中調用PowerShell腳本

[英]Calling PowerShell script inside guest VM with PowerCLI Invoke-VMScript

在來賓VM中,我有一個執行某些自動化操作的PowerShell腳本。 但是,我試圖使用PowerCLI從外部(在PowerShell內部)調用該PowerShell腳本。 目前,我的腳本可以運行,但不是在來賓VM中“運行” PowerShell腳本,而是將其作為文本文件打開。 另外,在來賓VM中,當我調用以下腳本時,會彈出一個交互式服務檢測。 我該如何解決這些問題?

add-pssnapin VMware.VimAutomation.Core 

Connect-VIServer 192.168.1.29 # connects to vCenter 

$vm = Get-VM -name 'CentOS 7'
$script = '"C:\Automation\StartServices.ps1"'
Invoke-VMScript -vm $vm -ScriptText $script -GuestUser 'user' - GuestPassword 'password' -ScriptType Powershell

$script路徑中使用單引號或雙引號,但不能同時使用:

$script = 'C:\Automation\StartServices.ps1'

這似乎是唯一的問題。 經過測試並在PowerCLI環境中工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM