简体   繁体   English

使用powershell脚本安装软件

[英]Install software using powershell script

I am trying to install Notepad++ software using a PowerShell v2.0 script for one of my POC.我正在尝试使用 PowerShell v2.0 脚本为我的一个 POC 安装 Notepad++ 软件。 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

As I am very much new to powershell scripting, can you please help in this?由于我对 powershell 脚本非常陌生,您能帮忙吗? Is the above code right, or do I need to change anything else to install the software?上面的代码是否正确,还是我需要更改其他任何内容才能安装该软件?

There are a few different ways to do this.有几种不同的方法可以做到这一点。 The way you're doing it is fine, but I don't think you really want all those install parameters.你这样做的方式很好,但我认为你并不真正想要所有这些安装参数。

Start-Process 'C:\\Users\\kirnen\\Desktop\\A\\npp.7.5.Installer.exe' "/S"

The /S part means you want a silent install, so you won't see an install wizard, and won't be able to choose any options. /S部分意味着您需要静默安装,因此您不会看到安装向导,也无法选择任何选项。 Not a bad thing, just be sure that's what you want.不是坏事,只要确定这就是你想要的。 Take off the "/S" if you want to follow the graphical install wizard.如果您想遵循图形安装向导,请取消"/S"

Instead of Start-Process you can also use cmd /c and just & .除了Start-Process您还可以使用cmd /c和 just & These have their advantages and disadvantages.这些都有其优点和缺点。 Stick with Start-Process for now.现在坚持使用Start-Process

One last thing, with many .exe files you can follow them with /help or /?最后一件事,对于许多 .exe 文件,您可以使用/help/? to get a list of their command line switches.获取他们的命令行开关列表。

I use this snippet of PowerShell code for a lot of installs.我使用这段 PowerShell 代码进行了大量安装。 As long as you can figure out the silent switch for ".exe's".只要你能找出“.exe”的静音开关。 For ".msi's" just change out where Create() with Create("msiexec /IC:\\temp\\generic.msi /qn")对于“.msi”,只需将Create()更改为Create("msiexec /IC:\\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 
  }
}

#Install Chocolatey Provider #安装巧克力供应商

Get-Package -Provider chocolatey -Force

#Install Software #安装软件

Install-Package adobereader, 7zip, anydesk, firefox, notepadplusplus, teamviewer, vlc -Force

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM