【问题标题】:Install remotely with powershell使用 powershell 远程安装
【发布时间】:2015-12-08 10:38:36
【问题描述】:

我想构建一个远程安装 HP OM 代理的脚本。有没有什么好的方法来安装它,而无需在远程计算机上安装安装文件? 此脚本将为服务器列表远程安装 HP 代理。我想将文件从我的计算机复制到每个服务器,然后安装它。我确信有更好的方法来做到这一点。 要安装代理,我需要运行以下命令: cscript "\c:\pathToTheAgentFile" -i -a -minprecheck

【问题讨论】:

  • 您能告诉我们远程计算机上可用的 PowerShell 版本吗?
  • 它在 2-3 之间,在我的电脑上是 4。假设有什么不同吗?
  • 是的,可用的 cmdlet 和其他会影响脚本创建方式的功能。
  • 我需要什么版本?
  • 任何版本都可以工作,知道可用的版本将限制可以使用的 cmdlet 并影响其他注意事项。

标签: powershell vbscript automation powershell-remoting wsh


【解决方案1】:

只要使用静默安装方法,使用带有 ScriptBlock 参数的 Invoke-Command 即可完成此任务。

$ComputersList = @("computer","names","here","replace","me")
$PathToShare = "\\path\to\install_replace_me.exe"
$CommonLocalComputerPath = "C:\replace_me.exe"
$SilentInstallArgs = "/example","/replace"
$AdministratorCreds = [System.Management.Automation.PSCredential]::Empty

$ComputersList | ForEach-Object {
    Invoke-Command -ComputerName $_ -ScriptBlock { Copy-Item $Using:PathToShare -Destination $Using:CommonLocalComputerPath -Credential $Using:AdministratorCreds;
    Start-Process $Using:CommonLocalComputerPath -ArgumentList $Using:SilentInstallArgs -Credential $Using:AdministratorCreds} -Credential $AdministratorCreds
}

上述脚本将提示输入管理凭据,从远程计算机对保存安装程序的远程共享进行身份验证,将安装程序复制到远程计算机,然后在远程计算机上启动安装程序。您必须手动验证安装,因为它不会返回任何数据,除非发生终止错误。必须修改脚本以指向您环境的正确位置。

【讨论】:

  • 要安装代理,我需要运行命令:cscript path -i -a -minprechek,我应该把它放在脚本的哪里?
  • 你能告诉在 $SilentInstallArgs 中放什么吗?我如何将我的用户放入 $AdministratorCreds? $PathToShare 和 $CommonLocalComputerPath 有什么区别?我在您的脚本中没有看到您调用 $ComputersList 的任何地方
  • 您将在 $SilentInstallArgs 中放置的内容基于 HP OM 代理静默安装所需的参数,我不知道它们。当您从您的计算机运行脚本时,系统将自动提示您输入凭据,凭据必须是在服务器上具有安装访问权限的凭据。 $PathToShare 是服务器可以访问的 HP OP 代理安装程序的位置。 $CommonLocalComputerPath 是服务器将从共享位置放置 HP OM 安装程序副本的位置。 $ComputerList 是一个错字,我已经修正了。
猜你喜欢
  • 2015-07-06
  • 1970-01-01
  • 1970-01-01
  • 2022-10-22
  • 2014-03-12
  • 1970-01-01
  • 2018-03-07
  • 2019-03-19
  • 2021-07-05
相关资源
最近更新 更多