使用powershell脚本安装软件 [英] Install software using powershell script

查看:219
本文介绍了使用powershell脚本安装软件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PowerShell v2.0 脚本为我的一个 POC 安装 Notepad++ 软件.我需要在我当前的项目中安装客户端的软件.当我运行以下脚本时,出现错误.

I am trying to install Notepad++ software using a PowerShell v2.0 script for one of my POC. I need to install the client's software in my current project. As I am running the below script I'm getting errors.

Start-Process 'C:\Users\kirnen\Desktop\A\npp.7.5.Installer.exe'-InstallerParameters "/S" `
-RegistryKey HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Notepad++ `
-RegistryName DisplayVersion -RegistryValue 7.5

由于我对 powershell 脚本非常陌生,请问您能帮忙解决这个问题吗?上面的代码是对的,还是我需要改变什么才能安装软件?

As I am very much new to powershell scripting, can you please help in this? Is the above code right, or do I need to change anything else to install the software?

推荐答案

我将这段 PowerShell 代码用于很多安装.只要你能找出.exe"的静音开关.对于.msi",只需将 Create() 的位置更改为 Create("msiexec/I C:\temp\generic.msi/qn")

I use this snippet of PowerShell code for a lot of installs. As long as you can figure out the silent switch for ".exe's". For ".msi's" just change out where Create() with Create("msiexec /I C:\temp\generic.msi /qn")

$computers = c:\temp\computerName.csv
$Notepad = "Location of notepad install"

$computers | where{test-connection $_ -quiet -count 1} | ForEach-Object {

  copy-item $Notepad -recurse "\\$_\c$\temp" 

  $newProc=([WMICLASS]"\\$_\root\cimv2:win32_Process").Create("C:\temp\npp.6.9.2.Installer.exe /S")

  If ($newProc.ReturnValue -eq 0) { 
    Write-Host $_ $newProc.ProcessId 
  } else { 
    write-host $_ Process create failed with $newProc.ReturnValue 
  }
}

这篇关于使用powershell脚本安装软件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆