脚本块PowerShell远程MSI安装

时间:2013-05-22 05:54:29

标签: powershell windows-installer powershell-v2.0

您好我正在尝试从构建机器A(cttfs)执行MSI并在机器B上安装该MSI(c2devint);输出是机器B上的网站。

请帮我修复机器A上带有MSI安装程序的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

还请帮我讲一下如何通过用户名&amp;转到这个脚本

1 个答案:

答案 0 :(得分:1)

由于您创建了PSSession,请使用New-PSSession上的-ComputerName参数。

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>]

Invoke-Command上的-Session参数移到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上的Invoke-Command参数,因为您使用的是Session参数集。

Parameter Set: Session
Invoke-Command [[-Session] <PSSession[]> ] [-ScriptBlock] <ScriptBlock> [-ArgumentList <Object[]> ] [-AsJob] [-HideComputerName] [-InputObject <PSObject> ] [-JobName <String> ] [-ThrottleLimit <Int32> ] [ <CommonParameters>]