使用 powershell 脚本安装软件
Install software using powershell script
我正在尝试使用 PowerShell v2.0 脚本为我的一个 POC 安装 Notepad++ 软件。我需要在我当前的项目中安装客户端的软件。因为我是 运行 下面的脚本,所以我遇到了错误。
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 脚本编写非常陌生,请问您能帮忙吗?上面的代码对吗,还是需要改什么才能安装软件?
有几种不同的方法可以做到这一点。你这样做的方式很好,但我不认为你真的想要所有这些安装参数。
Start-Process 'C:\Users\kirnen\Desktop\A\npp.7.5.Installer.exe' "/S"
/S
部分表示您需要静默安装,因此您不会看到安装向导,也无法选择任何选项。不是坏事,只要确定那是你想要的。如果您想按照图形安装向导进行操作,请取消 "/S"
。
您也可以使用 cmd /c
而不是 Start-Process
而只是 &
。这些都有其优点和缺点。暂时坚持 Start-Process
。
最后一件事,对于许多 .exe 文件,您可以使用 /help
或 /?
跟随它们以获取它们的命令行开关列表。
我使用这段 PowerShell 代码进行了很多次安装。只要你能弄清楚“.exe”的静默开关就可以了。对于“.msi”,只需将 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
}
}
#安装 Chocolatey Provider
Get-Package -Provider chocolatey -Force
#安装软件
Install-Package adobereader, 7zip, anydesk, firefox, notepadplusplus, teamviewer, vlc -Force
我用 Chocolatey 创建了一个 Powershell 脚本来执行 json 中列表中程序的安装。
它将安装 chocolatey,检查软件包,然后安装它们
查看存储库:https://github.com/SandimL/Powershell-automatic-installation
尝试使用 Winget 实用程序
Winget 在 cmd 或 powershell 终端上搜索“YourPackage”
然后拿走你想要的包然后做“Winget install YourPackage”
例如,我想安装 chrome :
Winget install Google.Chrome
我正在尝试使用 PowerShell v2.0 脚本为我的一个 POC 安装 Notepad++ 软件。我需要在我当前的项目中安装客户端的软件。因为我是 运行 下面的脚本,所以我遇到了错误。
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 脚本编写非常陌生,请问您能帮忙吗?上面的代码对吗,还是需要改什么才能安装软件?
有几种不同的方法可以做到这一点。你这样做的方式很好,但我不认为你真的想要所有这些安装参数。
Start-Process 'C:\Users\kirnen\Desktop\A\npp.7.5.Installer.exe' "/S"
/S
部分表示您需要静默安装,因此您不会看到安装向导,也无法选择任何选项。不是坏事,只要确定那是你想要的。如果您想按照图形安装向导进行操作,请取消 "/S"
。
您也可以使用 cmd /c
而不是 Start-Process
而只是 &
。这些都有其优点和缺点。暂时坚持 Start-Process
。
最后一件事,对于许多 .exe 文件,您可以使用 /help
或 /?
跟随它们以获取它们的命令行开关列表。
我使用这段 PowerShell 代码进行了很多次安装。只要你能弄清楚“.exe”的静默开关就可以了。对于“.msi”,只需将 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
}
}
#安装 Chocolatey Provider
Get-Package -Provider chocolatey -Force
#安装软件
Install-Package adobereader, 7zip, anydesk, firefox, notepadplusplus, teamviewer, vlc -Force
我用 Chocolatey 创建了一个 Powershell 脚本来执行 json 中列表中程序的安装。
它将安装 chocolatey,检查软件包,然后安装它们
查看存储库:https://github.com/SandimL/Powershell-automatic-installation
尝试使用 Winget 实用程序
Winget 在 cmd 或 powershell 终端上搜索“YourPackage” 然后拿走你想要的包然后做“Winget install YourPackage” 例如,我想安装 chrome :
Winget install Google.Chrome