用于安装软件的Powershell脚本

用于安装软件的Powershell脚本,powershell,Powershell,我正在尝试制作一个可以与RMM工具一起使用的powershell脚本。因此,基本上这个powershell脚本将在本地机器上执行。它需要检查应用程序的版本是否已安装,并且至少有版本号xx。若并没有安装,或者版本更低,它将下载可执行文件并静默安装 我在网上找到了一个AdobeReader的例子,它确实可以工作,但它并没有进行事先检查。因此,该脚本将在每次运行时安装Adobe Reader $tempFolder=$Env:TEMP function runProcess ($cmd, $para

我正在尝试制作一个可以与RMM工具一起使用的powershell脚本。因此,基本上这个powershell脚本将在本地机器上执行。它需要检查应用程序的版本是否已安装,并且至少有版本号xx。若并没有安装,或者版本更低,它将下载可执行文件并静默安装

我在网上找到了一个AdobeReader的例子,它确实可以工作,但它并没有进行事先检查。因此,该脚本将在每次运行时安装Adobe Reader

$tempFolder=$Env:TEMP

function runProcess ($cmd, $params) {
$p = new-object System.Diagnostics.Process
$p.StartInfo = new-object System.Diagnostics.ProcessStartInfo
$exitcode = $false
$p.StartInfo.FileName = $cmd
$p.StartInfo.Arguments = $params
$p.StartInfo.UseShellExecute = $False
$p.StartInfo.RedirectStandardError = $True
$p.StartInfo.RedirectStandardOutput = $True
$p.StartInfo.WindowStyle = 1;
$null = $p.Start()
$p.WaitForExit()
$output = $p.StandardOutput.ReadToEnd()
$exitcode = $p.ExitCode
$p.Dispose()
$exitcode
$output
}

#download installer
invoke-webrequest "ftp://ftp.adobe.com/pub/adobe/reader/win/AcrobatDC/1500720033/AcroRdrDC1500720033_en_US.msi" -OutFile "$tempFolder\AcroRdrDC1500720033_en_US.msi" -ErrorAction Stop

#run installer
$res = runProcess msiexec "/i $tempFolder\AcroRdrDC1500720033_en_US.msi /qb"

#check if return code is 0
if(0 -ne $res[0]){
return "Failed to install Adobe Reader: $($res[0]) $($res[1])"
}

#download the patch
invoke-webrequest "ftp://ftp.adobe.com/pub/adobe/reader/win/AcrobatDC/1502320070/AcroRdrDCUpd1502320070.msp" -OutFile "$tempFolder\AcroRdrDCUpd1502320070.msp" -ErrorAction Stop

#install it
$res = runProcess msiexec "/p $tempFolder\AcroRdrDCUpd1502320070.msp /qb"

#check if return code is 0
if(0 -ne $res[0]){
return "Failed to install Adobe Reader DC Patch: $($res[0]) $($res[1])"
}else{
#Attempt to silently disable the auto updater if set in this script
new-itemproperty "HKLM:\Software\Policies\Adobe\Acrobat Reader\DC\FeatureLockDown" -name bUpdater -value 0 -ErrorAction SilentlyContinue
}
我认为在这个脚本中可能不需要一些东西。它也没有版本检查

在另一个站点上发现此问题,但不确定如何实施。而且,它看起来不像是在检查版本号

function Is-Installed( $program ) {

    $x86 = ((Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall") |
        Where-Object { $_.GetValue( "DisplayName" ) -like "*$program*" } ).Length -gt 0;

    $x64 = ((Get-ChildItem "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall") |
        Where-Object { $_.GetValue( "DisplayName" ) -like "*$program*" } ).Length -gt 0;

    return $x86 -or $x64;
}
理想情况下,我希望在顶部设置参数,以便为其他可执行文件使用模板。比如说

$app_name
$app_version
$app_url
$app_filename
$app_executable
$app_arguments

任何帮助都将不胜感激。

我做了更多的挖掘,发现了这篇文章:

允许匹配名称和版本:

$tempdir = Get-Location
$tempdir = $tempdir.tostring()
$appName = '*AirParrot*'
$appVersion = "2.6.8"
$msiFile = $tempdir+"\microsoft.interopformsredist.msi"
$msiArgs = "-qb"

function Get-InstalledApps
{
    if ([IntPtr]::Size -eq 4) {
        $regpath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
    }
    else {
        $regpath = @(
            'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
            'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
        )
    }
    Get-ItemProperty $regpath | .{process{if($_.DisplayName -and $_.UninstallString) { $_ } }} | Select DisplayName, Publisher, InstallDate, DisplayVersion, UninstallString |Sort DisplayName

}

$result = Get-InstalledApps | where {$_.DisplayName -like $appName -and $_.DisplayVersion -ge $appVersion}

If ($result -eq $null) {
    (Start-Process -FilePath $msiFile -ArgumentList $msiArgs -Wait -Passthru).ExitCode
}

有什么帮助吗?为您设计一个交钥匙解决方案?(这不是这个网站的目的。)我刚刚意识到我的网站没有比较版本。