chrome安装好之后默认在windows下是通过任务计划程序会自动更新程序,更新内核。 有时候我们需要立刻安装chrome的更新,而且是大批量更新,这个时候一台台去更新显得很费时间。

这里写一段powershell 更新chrome 浏览器

#函数获取是否安装了chrome浏览器,如果安装了,返回他的版本号
function GetInstalledChromeVer() {
    $path = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe').'(Default)'
    return (Get-Item $path).VersionInfo.ProductVersion
}

#函数获取目前谷歌chrome最新版本号
function GetLatestChromeVer() {
    # omahaproxy CSV
    $csv = (Invoke-WebRequest -Uri https://omahaproxy.appspot.com/all).Content
    return $csv | ConvertFrom-Csv | Where-Object { $_.os -eq 'win' -and $_.channel -eq 'stable' } | Select-Object -ExpandProperty current_version
}


#通过判断是否存在谷歌浏览器安装,之后比较版本,如果是最新版本,则退出
 if((Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe').'(Default)'){
    $currVer = GetInstalledChromeVer
    $latestVer = GetLatestChromeVer 
    if ($currVer -eq $latestVer) {
    Write-Host "Chrome 已是最新版本 $latestVer" -ForegroundColor Green
    exit 
}
else {
    $msg = "Chrome 版本过旧:$currVer 请更新至 $latestVer"
    Write-Host $msg -ForegroundColor Red
#如果不是最新版本,则开始按照谷歌浏览器的升级的方式,升级google版本,升级后需要人工重新打开chrome浏览器才会显示最新版本,如果没打开过,会一直显示是旧版本
#其中参考任务计划自带的命令升级chrome,但是powershell脚本运行会提示异常,故通过进入目录执行,原先命令为
#"C:\Program Files (x86)\Google\Update\GoogleUpdate.exe"  /ua /installsource scheduler
#"C:\Program Files (x86)\Google\Update\GoogleUpdate.exe"  /c
    cd "C:\Program Files (x86)\Google\Update\"
    pwd
    .\GoogleUpdate.exe /ua /installsource scheduler
    .\GoogleUpdate.exe /c

}
     
 }else{
     
 }