2

嗨,我试图从构建机器 A(cttfs)执行 MSI 并将该 MSI 安装在机器 B(c2devint)上;输出是机器 B 上的网站。

请帮助我使用 MSI 安装程序修复机器 A 上的 powershell 脚本。此脚本从机器 A 运行

$cred = Get-Credential username
$session = new-PSSession -name c2devint -credential $cred
Invoke-Command -ScriptBlock {Invoke-Command -Session $session -ScriptBlock {Start-Process "msiexec.exe" -ArgumentList "/i C:\DailyBuild\DirectMSI.msi INSTALLLOCATION=D:\Websites\DirectDevInt ENVPROPERTY=DEV /qb" -Wait} -ComputerName c2devint}
Remove-PSSession $session

这是错误

 Invoke-Command : Parameter set cannot be resolved using the specified named parameters.
    At line:3 char:44
    + Invoke-Command -ScriptBlock {Invoke-Command <<<<  -Session $session -ScriptBlock {Start-Process "msiexec.exe" -ArgumentList "/i C:\DailyBuild\DirectMSI.msi INSTALLLOCATION=D:\Websites\DirectDevInt ENVPROPERTY=DEV /qb" -Wait} -ComputerName c2devint}
        + CategoryInfo          : InvalidArgument: (:) [Invoke-Command], ParameterBindingException
        + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeCommandCommand

还请帮助我如何将用户名和密码传递给这个脚本

4

1 回答 1

1

由于您创建了 PSSession,因此请使用-ComputerName参数 on New-PSSession

Parameter Set: ComputerName
New-PSSession [[-ComputerName] <String[]> ] [-ApplicationName <String> ] [-Authentication <AuthenticationMechanism> ] [-CertificateThumbprint <String> ] [-ConfigurationName <String> ] [-Credential <PSCredential> ] [-EnableNetworkAccess] [-Name <String[]> ] [-Port <Int32> ] [-SessionOption <PSSessionOption> ] [-ThrottleLimit <Int32> ] [-UseSSL] [ <CommonParameters>]

-Session参数Invoke-Command移到脚本块之外:

Invoke-Command -Session $session -ScriptBlock `
    {Start-Process "msiexec.exe" -ArgumentList "/i C:\DailyBuild\DirectMSI.msi INSTALLLOCATION=D:\Websites\DirectDevInt ENVPROPERTY=DEV /qb" -Wait}

然后删除-ComputerName参数 on,Invoke-Command因为您正在使用Session参数集。

Parameter Set: Session
Invoke-Command [[-Session] <PSSession[]> ] [-ScriptBlock] <ScriptBlock> [-ArgumentList <Object[]> ] [-AsJob] [-HideComputerName] [-InputObject <PSObject> ] [-JobName <String> ] [-ThrottleLimit <Int32> ] [ <CommonParameters>]
于 2013-05-22T06:07:36.943 回答