简体   繁体   English

使用invoke-vmscript从powercli脚本调用powershell脚本?

[英]Calling a powershell script from a powercli script using invoke-vmscript?

I am attempting to execute a .ps1 on multiple VM's using the invoke-VMScript function. 我正在尝试使用invoke-VMScript函数在多个VM上执行.ps1。 Currently I have the code: Invoke-VMScript -ScriptText $script -VM $servername -guestcredential $gcred -hostcredential $hcred and have $script = 'data.ps1' however this returns the error stating that 'data.ps1' is not a valid function or script. 当前,我有以下代码: Invoke-VMScript -ScriptText $script -VM $servername -guestcredential $gcred -hostcredential $hcred并具有$script = 'data.ps1'但这返回错误,表明'data.ps1'不是有效的函数或脚本。 Any help is greatly appreciated. 任何帮助是极大的赞赏。

I'm not set up to test this, but I would guess that -ScriptText needs to be given the full path to a .ps1 file accessible on the VM. 我没有进行测试,但是我猜想-ScriptText需要提供VM上可访问的.ps1文件的完整路径。

$script = '"C:\my scripts\data.ps1"'
Invoke-VMScript -ScriptText $script -VM $servername -guestcredential $gcred -hostcredential $hcred

您必须输入脚本的脚本变量内容,而不是文件名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM