gpt4 book ai didi

powershell - 脚本 block Powershell远程MSI安装

转载 作者:行者123 更新时间:2023-12-03 00:03:10 24 4
gpt4 key购买 nike

嗨,我正在尝试从构建计算机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

另外请帮助我如何将用户名和密码传递给此脚本

最佳答案

自创建PSSession之后,请在 -ComputerName 上使用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参数集,所以请删除 Invoke-Command上的 Session参数。
Parameter Set: Session
Invoke-Command [[-Session] <PSSession[]> ] [-ScriptBlock] <ScriptBlock> [-ArgumentList <Object[]> ] [-AsJob] [-HideComputerName] [-InputObject <PSObject> ] [-JobName <String> ] [-ThrottleLimit <Int32> ] [ <CommonParameters>]

关于powershell - 脚本 block Powershell远程MSI安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16684418/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com