Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install software using powershell script

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

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?

like image 498
kiran n Avatar asked Jan 30 '23 18:01

kiran n


1 Answers

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 
  }
}
like image 185
MattMoo Avatar answered Feb 11 '23 23:02

MattMoo