Optimisations
parent
233f039323
commit
013ab2d7fd
|
@ -0,0 +1,34 @@
|
||||||
|
Function Get-WingetCmd {
|
||||||
|
#Get WinGet Path (if admin context)
|
||||||
|
$ResolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe"
|
||||||
|
if ($ResolveWingetPath){
|
||||||
|
#If multiple version, pick last one
|
||||||
|
$WingetPath = $ResolveWingetPath[-1].Path
|
||||||
|
}
|
||||||
|
|
||||||
|
#Get Winget Location in User context
|
||||||
|
$WingetCmd = Get-Command winget.exe -ErrorAction SilentlyContinue
|
||||||
|
if ($WingetCmd){
|
||||||
|
$Script:Winget = $WingetCmd.Source
|
||||||
|
}
|
||||||
|
#Get Winget Location in System context (WinGet < 1.17)
|
||||||
|
elseif (Test-Path "$WingetPath\AppInstallerCLI.exe"){
|
||||||
|
$Script:Winget = "$WingetPath\AppInstallerCLI.exe"
|
||||||
|
}
|
||||||
|
#Get Winget Location in System context (WinGet > 1.17)
|
||||||
|
elseif (Test-Path "$WingetPath\winget.exe"){
|
||||||
|
$Script:Winget = "$WingetPath\winget.exe"
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Write-Log "Winget not installed or detected !" "Red"
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
|
||||||
|
#Run winget to list apps and accept source agrements (necessary on first run)
|
||||||
|
& $Winget list --accept-source-agreements | Out-Null
|
||||||
|
|
||||||
|
#Log Winget installed version
|
||||||
|
$WingerVer = & $Winget --version
|
||||||
|
Write-Log "Winget Version: $WingerVer"
|
||||||
|
return $true
|
||||||
|
}
|
|
@ -6,38 +6,6 @@ function Get-WingetOutdatedApps {
|
||||||
[string]$AvailableVersion
|
[string]$AvailableVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
#Get WinGet Path (if admin context)
|
|
||||||
$ResolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe"
|
|
||||||
if ($ResolveWingetPath){
|
|
||||||
#If multiple version, pick last one
|
|
||||||
$WingetPath = $ResolveWingetPath[-1].Path
|
|
||||||
}
|
|
||||||
|
|
||||||
#Get Winget Location in User context
|
|
||||||
$WingetCmd = Get-Command winget.exe -ErrorAction SilentlyContinue
|
|
||||||
if ($WingetCmd){
|
|
||||||
$Script:Winget = $WingetCmd.Source
|
|
||||||
}
|
|
||||||
#Get Winget Location in System context (WinGet < 1.17)
|
|
||||||
elseif (Test-Path "$WingetPath\AppInstallerCLI.exe"){
|
|
||||||
$Script:Winget = "$WingetPath\AppInstallerCLI.exe"
|
|
||||||
}
|
|
||||||
#Get Winget Location in System context (WinGet > 1.17)
|
|
||||||
elseif (Test-Path "$WingetPath\winget.exe"){
|
|
||||||
$Script:Winget = "$WingetPath\winget.exe"
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
Write-Log "Winget not installed !" "Red"
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
#Run winget to list apps and accept source agrements (necessary on first run)
|
|
||||||
& $Winget list --accept-source-agreements | Out-Null
|
|
||||||
|
|
||||||
#Log Winget installed version
|
|
||||||
$WingerVer = & $Winget --version
|
|
||||||
Write-Log "Winget Version: $WingerVer"
|
|
||||||
|
|
||||||
#Get list of available upgrades on winget format
|
#Get list of available upgrades on winget format
|
||||||
Write-Log "Checking application updates on Winget Repository..." "yellow"
|
Write-Log "Checking application updates on Winget Repository..." "yellow"
|
||||||
$upgradeResult = & $Winget upgrade | Out-String
|
$upgradeResult = & $Winget upgrade | Out-String
|
||||||
|
|
|
@ -16,88 +16,91 @@ Get-NotifLocale
|
||||||
|
|
||||||
#Check network connectivity
|
#Check network connectivity
|
||||||
if (Test-Network){
|
if (Test-Network){
|
||||||
#Get Current Version
|
$TestWinget = Get-WingetCmd
|
||||||
Get-WAUCurrentVersion
|
if ($TestWinget){
|
||||||
#Check if WAU update feature is enabled
|
#Get Current Version
|
||||||
Get-WAUUpdateStatus
|
Get-WAUCurrentVersion
|
||||||
#If yes then check WAU update
|
#Check if WAU update feature is enabled
|
||||||
if ($true -eq $WAUautoupdate){
|
Get-WAUUpdateStatus
|
||||||
#Get Available Version
|
#If yes then check WAU update
|
||||||
Get-WAUAvailableVersion
|
if ($true -eq $WAUautoupdate){
|
||||||
#Compare
|
#Get Available Version
|
||||||
if ([version]$WAUAvailableVersion -gt [version]$WAUCurrentVersion){
|
Get-WAUAvailableVersion
|
||||||
#If new version is available, update it
|
#Compare
|
||||||
Write-Log "WAU Available version: $WAUAvailableVersion" "Yellow"
|
if ([version]$WAUAvailableVersion -gt [version]$WAUCurrentVersion){
|
||||||
Update-WAU
|
#If new version is available, update it
|
||||||
|
Write-Log "WAU Available version: $WAUAvailableVersion" "Yellow"
|
||||||
|
Update-WAU
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Write-Log "WAU is up to date." "Green"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Get White or Black list
|
||||||
|
Get-WAUConfig
|
||||||
|
if ($UseWhiteList){
|
||||||
|
$toUpdate = Get-IncludedApps
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
Write-Log "WAU is up to date." "Green"
|
$toSkip = Get-ExcludedApps
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#Get White or Black list
|
#Get outdated Winget packages
|
||||||
Get-WAUConfig
|
$outdated = Get-WingetOutdatedApps
|
||||||
if ($UseWhiteList){
|
|
||||||
$toUpdate = Get-IncludedApps
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
$toSkip = Get-ExcludedApps
|
|
||||||
}
|
|
||||||
|
|
||||||
#Get outdated Winget packages
|
#Log list of app to update
|
||||||
$outdated = Get-WingetOutdatedApps
|
|
||||||
|
|
||||||
#Log list of app to update
|
|
||||||
foreach ($app in $outdated){
|
|
||||||
#List available updates
|
|
||||||
$Log = "Available update : $($app.Name). Current version : $($app.Version). Available version : $($app.AvailableVersion)."
|
|
||||||
$Log | Write-host
|
|
||||||
$Log | out-file -filepath $LogFile -Append
|
|
||||||
}
|
|
||||||
|
|
||||||
#Count good update installations
|
|
||||||
$Script:InstallOK = 0
|
|
||||||
|
|
||||||
#If White List
|
|
||||||
if ($UseWhiteList){
|
|
||||||
#For each app, notify and update
|
|
||||||
foreach ($app in $outdated){
|
foreach ($app in $outdated){
|
||||||
if (($toUpdate -contains $app.Id) -and $($app.Version) -ne "Unknown"){
|
#List available updates
|
||||||
Update-App $app
|
$Log = "Available update : $($app.Name). Current version : $($app.Version). Available version : $($app.AvailableVersion)."
|
||||||
}
|
$Log | Write-host
|
||||||
#if current app version is unknown
|
$Log | out-file -filepath $LogFile -Append
|
||||||
elseif($($app.Version) -eq "Unknown"){
|
}
|
||||||
Write-Log "$($app.Name) : Skipped upgrade because current version is 'Unknown'" "Gray"
|
|
||||||
}
|
#Count good update installations
|
||||||
#if app is in "excluded list"
|
$Script:InstallOK = 0
|
||||||
else{
|
|
||||||
Write-Log "$($app.Name) : Skipped upgrade because it is not in the included app list" "Gray"
|
#If White List
|
||||||
|
if ($UseWhiteList){
|
||||||
|
#For each app, notify and update
|
||||||
|
foreach ($app in $outdated){
|
||||||
|
if (($toUpdate -contains $app.Id) -and $($app.Version) -ne "Unknown"){
|
||||||
|
Update-App $app
|
||||||
|
}
|
||||||
|
#if current app version is unknown
|
||||||
|
elseif($($app.Version) -eq "Unknown"){
|
||||||
|
Write-Log "$($app.Name) : Skipped upgrade because current version is 'Unknown'" "Gray"
|
||||||
|
}
|
||||||
|
#if app is in "excluded list"
|
||||||
|
else{
|
||||||
|
Write-Log "$($app.Name) : Skipped upgrade because it is not in the included app list" "Gray"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
#If Black List
|
||||||
#If Black List
|
else{
|
||||||
else{
|
#For each app, notify and update
|
||||||
#For each app, notify and update
|
foreach ($app in $outdated){
|
||||||
foreach ($app in $outdated){
|
if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne "Unknown"){
|
||||||
if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne "Unknown"){
|
Update-App $app
|
||||||
Update-App $app
|
}
|
||||||
}
|
#if current app version is unknown
|
||||||
#if current app version is unknown
|
elseif($($app.Version) -eq "Unknown"){
|
||||||
elseif($($app.Version) -eq "Unknown"){
|
Write-Log "$($app.Name) : Skipped upgrade because current version is 'Unknown'" "Gray"
|
||||||
Write-Log "$($app.Name) : Skipped upgrade because current version is 'Unknown'" "Gray"
|
}
|
||||||
}
|
#if app is in "excluded list"
|
||||||
#if app is in "excluded list"
|
else{
|
||||||
else{
|
Write-Log "$($app.Name) : Skipped upgrade because it is in the excluded app list" "Gray"
|
||||||
Write-Log "$($app.Name) : Skipped upgrade because it is in the excluded app list" "Gray"
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if ($InstallOK -gt 0){
|
||||||
if ($InstallOK -gt 0){
|
Write-Log "$InstallOK apps updated ! No more update." "Green"
|
||||||
Write-Log "$InstallOK apps updated ! No more update." "Green"
|
}
|
||||||
}
|
if ($InstallOK -eq 0){
|
||||||
if ($InstallOK -eq 0){
|
Write-Log "No new update." "Green"
|
||||||
Write-Log "No new update." "Green"
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue