【问题标题】:Invoke-VMScript PowerCLI 6.5 Call Script with ParametersInvoke-VMScript PowerCLI 6.5 带参数的调用脚本
【发布时间】:2017-06-06 09:29:22
【问题描述】:

我目前正在开发一个脚本,它应该能够将某个 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

不会透露太多调用脚本的使用参数。

【问题讨论】:

    标签: powershell powercli


    【解决方案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
    

    【讨论】:

      【解决方案2】:

      这是我用的

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-23
        • 2019-03-24
        相关资源
        最近更新 更多