Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 使用参数调用VMScript PowerCLI 6.5调用脚本_Powershell_Powercli - Fatal编程技术网

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

Powershell 使用参数调用VMScript PowerCLI 6.5调用脚本,powershell,powercli,Powershell,Powercli,我目前正在开发一个脚本,它应该能够在主机系统中将某个Windows共享连接为带有驱动器号的网络驱动器。由于Windows共享是动态的(几乎每次调用脚本get时都会发生更改),因此我需要将其作为参数传递给VM上运行的脚本 我现在拥有的 在我的脚本中调用存储在我的计算机上的脚本 MainScript.ps1包含 $MyVMName = "somevmname" $Script = "C:\path\to\script\somescript.ps1 -Path \\some\shared\folder

我目前正在开发一个脚本,它应该能够在主机系统中将某个Windows共享连接为带有驱动器号的网络驱动器。由于Windows共享是动态的(几乎每次调用脚本get时都会发生更改),因此我需要将其作为参数传递给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
Param(
      [Parameter(Mandatory=$true)]
      $Path,
      [Parameter(Mandatory=$true)]
      $Credentials
)

New-PSDrive -Name "H" -PSProvider FileSystem -Root $Path -Credential $Credentials 
somescript.ps1包含

$MyVMName = "somevmname"
$Script = "C:\path\to\script\somescript.ps1 -Path \\some\shared\folder"
Invoke-VMScript -VM $MyVMName -ScriptText $Script -ScriptType PowerShell -GuestCredential $MyGuestCredential
Param(
      [Parameter(Mandatory=$true)]
      $Path,
      [Parameter(Mandatory=$true)]
      $Credentials
)

New-PSDrive -Name "H" -PSProvider FileSystem -Root $Path -Credential $Credentials 
每次执行MainScript.ps1时,当执行
Invoke VMScript
命令时,它很可能会冻结。是否有其他方法将参数传递给脚本

文件可在


使用调用的脚本的参数不会显示太多信息。

您可以尝试创建一个运行该脚本的新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
这就是我用的

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