基本上我想这样做:
foreach ($SERVER_NAME in $SERVER_NAME_LIST)
{
$SESSION = New-PSSession -ComputerName $SERVER_NAME -Credential $CRED
Invoke-Command -Session $SESSION -ScriptBlock
{
Write-Zip -Path $PATH -OutputPath test.zip -IncludeEmptyDirectories
}
}
我收到此错误:
The term 'Write-Zip' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
我是否真的必须在everey远程机器上安装扩展程序并每次调用import module
?
提前感谢您的帮助
答案 0 :(得分:0)
是的,您需要在每台远程计算机上安装,因为invoke-command将在远程计算机上运行commond。如果您使用的是Powershell v3,则无需手动导入,因为PSV3可以自动导入模块,但如果您使用的是powershell-v2,则需要导入-scriptblock {ipmo path\to\module}