2022-04-13 16:50:06 +00:00
|
|
|
#Function to get outdated app list, in formatted array
|
|
|
|
|
2022-03-22 13:39:01 +00:00
|
|
|
function Get-WingetOutdatedApps {
|
2022-03-14 13:55:02 +00:00
|
|
|
class Software {
|
|
|
|
[string]$Name
|
|
|
|
[string]$Id
|
|
|
|
[string]$Version
|
|
|
|
[string]$AvailableVersion
|
|
|
|
}
|
|
|
|
|
|
|
|
#Get list of available upgrades on winget format
|
2022-04-08 16:37:59 +00:00
|
|
|
Write-Log "Checking application updates on Winget Repository..." "yellow"
|
2022-07-06 15:43:51 +00:00
|
|
|
$upgradeResult = & $Winget upgrade --source winget | Out-String
|
2022-03-14 13:55:02 +00:00
|
|
|
|
|
|
|
#Start Convertion of winget format to an array. Check if "-----" exists
|
2022-06-10 08:26:41 +00:00
|
|
|
if (!($upgradeResult -match "-----")) {
|
2022-03-14 13:55:02 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
#Split winget output to lines
|
2022-07-07 15:02:41 +00:00
|
|
|
$lines = $upgradeResult.Split([Environment]::NewLine) | Where-Object { $_ -and $_ -notmatch "--include-unknown" }
|
2022-03-14 13:55:02 +00:00
|
|
|
|
|
|
|
# Find the line that starts with "------"
|
|
|
|
$fl = 0
|
2022-06-10 08:26:41 +00:00
|
|
|
while (-not $lines[$fl].StartsWith("-----")) {
|
2022-03-14 13:55:02 +00:00
|
|
|
$fl++
|
|
|
|
}
|
|
|
|
|
2022-04-07 22:50:28 +00:00
|
|
|
#Get header line
|
|
|
|
$fl = $fl - 1
|
2022-03-14 13:55:02 +00:00
|
|
|
|
|
|
|
#Get header titles
|
|
|
|
$index = $lines[$fl] -split '\s+'
|
|
|
|
|
2022-04-08 16:30:58 +00:00
|
|
|
# Line $fl has the header, we can find char where we find ID and Version
|
2022-03-14 13:55:02 +00:00
|
|
|
$idStart = $lines[$fl].IndexOf($index[1])
|
|
|
|
$versionStart = $lines[$fl].IndexOf($index[2])
|
|
|
|
$availableStart = $lines[$fl].IndexOf($index[3])
|
|
|
|
|
|
|
|
# Now cycle in real package and split accordingly
|
|
|
|
$upgradeList = @()
|
2022-07-06 15:43:51 +00:00
|
|
|
For ($i = $fl + 2; $i -lt $lines.Length -1; $i++) {
|
2022-03-14 13:55:02 +00:00
|
|
|
$line = $lines[$i]
|
2022-07-06 15:43:51 +00:00
|
|
|
if ($line) {
|
2022-03-14 13:55:02 +00:00
|
|
|
$software = [Software]::new()
|
|
|
|
$software.Name = $line.Substring(0, $idStart).TrimEnd()
|
|
|
|
$software.Id = $line.Substring($idStart, $versionStart - $idStart).TrimEnd()
|
|
|
|
$software.Version = $line.Substring($versionStart, $availableStart - $versionStart).TrimEnd()
|
2022-07-06 15:43:51 +00:00
|
|
|
$software.AvailableVersion = $line.Substring($availableStart).TrimEnd()
|
2022-03-14 13:55:02 +00:00
|
|
|
#add formated soft to list
|
|
|
|
$upgradeList += $software
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-03 22:56:44 +00:00
|
|
|
#If current user is not system, remove system apps from list
|
|
|
|
if ($currentPrincipal -eq $true) {
|
|
|
|
$SystemApps = Get-Content -Path "$WorkingDir\winget_system_apps.txt"
|
|
|
|
$upgradeList = $upgradeList | Where-Object {$SystemApps -notcontains $_}
|
|
|
|
}
|
2022-10-03 23:10:44 +00:00
|
|
|
else {
|
|
|
|
Get-WingetSystemApps
|
|
|
|
}
|
2022-10-03 22:56:44 +00:00
|
|
|
|
2022-08-10 08:57:09 +00:00
|
|
|
return $upgradeList | Sort-Object {Get-Random}
|
2022-10-03 22:56:44 +00:00
|
|
|
}
|