使用参数调用-VMScript PowerCLI 6.5调用脚本

时间:2017-06-06 09:29:23

标签: powershell powercli

我目前正在开发一个脚本,该脚本应该能够将某个Windows共享作为网络驱动器附加到主机系统中的驱动器号。由于Windows共享是动态的(几乎所有时间都可以更改脚本调用。)我需要将此作为参数传递给VM上运行的脚本。

我现在有什么。

在我的脚本中调用存储在我机器上的脚本。

MainScript.ps1包含。

$MyVMName = "somevmname"
$Script = "C:\path\to\script\somescript.ps1 -Path \\some\shared\folder"
Invoke-VMScript -VM $MyVMName -ScriptText $Script -ScriptType PowerShell -GuestCredential $MyGuestCredential

somescript.ps1包含。

Param(
      [Parameter(Mandatory=$true)]
      $Path,
      [Parameter(Mandatory=$true)]
      $Credentials
)

New-PSDrive -Name "H" -PSProvider FileSystem -Root $Path -Credential $Credentials 

每次我执行我的MainScript.ps1时,很可能在执行Invoke-VMScript命令时冻结。是否有另一种方法将参数传递给脚本?

下的文档

https://pubs.vmware.com/vsphere-65/index.jsp#com.vmware.powercli.cmdletref.doc/Invoke-VMScript.html

没有为调用的脚本显示过多的使用参数。

2 个答案:

答案 0 :(得分:1)

您可以尝试创建运行脚本的新PowerShell:

$MyVMName = "somevmname"
Invoke-VMScript -VM $MyVMName -ScriptText "powershell.exe -file C:\path\to\script\somescript.ps1 -Path \\some\shared\folder" -ScriptType PowerShell -GuestCredential $MyGuestCredential

答案 1 :(得分:0)

这就是我使用的

Invoke-VMScript -vm $vm -ScriptText {Start-Process "C:\Temp\Install.exe" -Verb runas "-q" -wait }
相关问题