首页 文章

使用powershell脚本安装软件

提问于
浏览
1

我正在尝试使用PowerShell v2.0脚本为我的一个POC安装记事本软件 . 我需要在当前项目中安装客户端软件 . 当我运行下面的脚本时,我遇到了错误 .

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脚本非常陌生,你能帮忙吗?上面的代码是正确的,还是我需要更改其他任何东西来安装软件?

2 回答

  • 1

    我使用这段PowerShell代码进行了大量安装 . 只要你能找出".exe's"的静音开关 . 对于".msi's"只需更改 Create()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 
      }
    }
    
  • 2

    有几种不同的方法可以做到这一点 . 你这样做的方式很好,但我不认为你真的想要所有这些安装参数 .

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

    /S 部分表示您需要静默安装,因此您赢得了't see an install wizard, and won' t能够选择任何选项 . 这不是一件坏事,只要确定这就是你想要的 . 如果要按照图形安装向导,请取消 "/S" .

    而不是 Start-Process ,你也可以使用 cmd /c 而只是 & . 这些都有其优点和缺点 . 现在坚持使用 Start-Process .

    最后一件事,使用许多.exe文件,您可以使用 /help/? 来获取它们的命令行开关列表 .

相关问题