朋友的我这个功能有问题,它会在远程服务器上运行,但我有以下输出:
调用命令:找不到接受参数“& C:\testNunit\dll\”的位置参数。在 D:\test\Multithread.ps1:65 char:16 + Invoke-Command <<<< -ComputerName $serv -ScriptBlock $command ([ScriptBlock]::Create("& $OneProject")) -credential $cred + CategoryInfo : InvalidArgument: (:) [Invoke-Command], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeCommandCommand
function Nunit {
##Parse connection parameters
$Connection = @{"server" = "..."; "username" = "..."; "password" = "...."}
$serv = $connection.Get_Item("server")
$user = $connection.Get_Item("username")
$pass = $connection.Get_Item("password")
$securePassword = ConvertTo-SecureString -AsPlainText $pass -Force
#Create connection credentials object for Invoke-Command
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $user, $securePassword
$NunitExe = "C:\testNunit\bin\nunit-console.exe"
$OneProject = "C:\testNunit\dll\Foundation.Tests.dll"
$TestProjects = "C:\testNunit\dll\"
foreach( $OneProject in ( $TestProjects))
{
$WorkingDir = "c:\testNunit"
$NUnitOutput = "c:\testNunit" + $OneProject + ".xml"
$command = {&"$NunitExe" "$WorkingDir\$OneProject" \noshadow/framework:"net-3.5" /xml:$NUnitOutput}
}
Invoke-Command -ComputerName $serv -ScriptBlock $command ([ScriptBlock]::Create("& $OneProject")) -credential $cred
}