Forums
New posts
Search forums
News
Security News
Technology News
Giveaways
Giveaways, Promotions and Contests
Discounts & Deals
Reviews
Users Reviews
Video Reviews
Support
Windows Malware Removal Help & Support
Inactive Support Threads
Mac Malware Removal Help & Support
Mobile Malware Removal Help & Support
Blog
Log in
Register
What's new
Search
Search titles only
By:
Search titles only
By:
Reply to thread
Menu
Install the app
Install
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Forums
Software
General Apps
System utilities
Winget app Updater Exclusion Script
Message
<blockquote data-quote="n8chavez" data-source="post: 978421" data-attributes="member: 90863"><p>There is another thread here about application updaters. One of the apps mentioned there was a somewhat-os-integrated updater called winget, which can be run via script for automation purposes. Winget is amazing by itself, because it can keep your apps updated silently. Not every application is listed, but a lot of popular software is listed.; at the time of this post there are 7111 packages in the repo. However it does have one flaw that I can see; users could not exclude software from being updated. In my case, I didn't want MS Edge being updated/reinstalled because I won't use it. I've come up with a powershell script to change that.</p><p></p><p>[CODE]class Software {</p><p> [string]$Name</p><p> [string]$Id</p><p> [string]$Version</p><p> [string]$AvailableVersion</p><p>}</p><p></p><p>$upgradeResult = winget upgrade | Out-String</p><p></p><p>$lines = $upgradeResult.Split([Environment]::NewLine)</p><p></p><p></p><p># Find the line that starts with Name, it contains the header</p><p>$fl = 0</p><p>while (-not $lines[$fl].StartsWith("Name"))</p><p>{</p><p> $fl++</p><p>}</p><p></p><p># Line $i has the header, we can find char where we find ID and Version</p><p>$idStart = $lines[$fl].IndexOf("Id")</p><p>$versionStart = $lines[$fl].IndexOf("Version")</p><p>$availableStart = $lines[$fl].IndexOf("Available")</p><p>$sourceStart = $lines[$fl].IndexOf("Source")</p><p></p><p># Now cycle in real package and split accordingly</p><p>$upgradeList = @()</p><p>For ($i = $fl + 1; $i -le $lines.Length; $i++)</p><p>{</p><p> $line = $lines[$i]</p><p> if ($line.Length -gt ($availableStart + 1) -and -not $line.StartsWith('-'))</p><p> {</p><p> $name = $line.Substring(0, $idStart).TrimEnd()</p><p> $id = $line.Substring($idStart, $versionStart - $idStart).TrimEnd()</p><p> $version = $line.Substring($versionStart, $availableStart - $versionStart).TrimEnd()</p><p> $available = $line.Substring($availableStart, $sourceStart - $availableStart).TrimEnd()</p><p> $software = [Software]::new()</p><p> $software.Name = $name;</p><p> $software.Id = $id;</p><p> $software.Version = $version</p><p> $software.AvailableVersion = $available;</p><p></p><p> $upgradeList += $software</p><p> }</p><p>}</p><p></p><p></p><p>$upgradeList | Format-Table</p><p></p><p>$toSkip = @(</p><p>'Microsoft.EdgeWebView2Runtime',</p><p>'Microsoft.Edge',</p><p>"Microsoft.OneDrive")</p><p></p><p>foreach ($package in $upgradeList)</p><p>{</p><p> if (-not ($toSkip -contains $package.Id))</p><p> {</p><p> Write-Host "Going to upgrade package $($package.id)"</p><p> & winget upgrade $package.id</p><p> }</p><p> else</p><p> {</p><p> Write-Host "Skipped upgrade to package $($package.id)"</p><p> }</p><p>}[/CODE]</p><p></p><p>Edit the colored exclusion entries to fit your needs. Also, you may want to consider creating a bat file, like the one below. That way the execution policy of powershell scripts will not be a problem. Change "scriptlocationandname" in the example below to the location and given name of the above powershell script.</p><p></p><p>[CODE]@echo off</p><p> </p><p>powershell.exe -ExecutionPolicy Unrestricted -Command ". 'C:\scriptlocationandname.ps1'"</p><p> </p><p>TIMEOUT /T 5[/CODE]</p><p></p><p>Anyways, that's it. I hope you find it useful.</p></blockquote><p></p>
[QUOTE="n8chavez, post: 978421, member: 90863"] There is another thread here about application updaters. One of the apps mentioned there was a somewhat-os-integrated updater called winget, which can be run via script for automation purposes. Winget is amazing by itself, because it can keep your apps updated silently. Not every application is listed, but a lot of popular software is listed.; at the time of this post there are 7111 packages in the repo. However it does have one flaw that I can see; users could not exclude software from being updated. In my case, I didn't want MS Edge being updated/reinstalled because I won't use it. I've come up with a powershell script to change that. [CODE]class Software { [string]$Name [string]$Id [string]$Version [string]$AvailableVersion } $upgradeResult = winget upgrade | Out-String $lines = $upgradeResult.Split([Environment]::NewLine) # Find the line that starts with Name, it contains the header $fl = 0 while (-not $lines[$fl].StartsWith("Name")) { $fl++ } # Line $i has the header, we can find char where we find ID and Version $idStart = $lines[$fl].IndexOf("Id") $versionStart = $lines[$fl].IndexOf("Version") $availableStart = $lines[$fl].IndexOf("Available") $sourceStart = $lines[$fl].IndexOf("Source") # Now cycle in real package and split accordingly $upgradeList = @() For ($i = $fl + 1; $i -le $lines.Length; $i++) { $line = $lines[$i] if ($line.Length -gt ($availableStart + 1) -and -not $line.StartsWith('-')) { $name = $line.Substring(0, $idStart).TrimEnd() $id = $line.Substring($idStart, $versionStart - $idStart).TrimEnd() $version = $line.Substring($versionStart, $availableStart - $versionStart).TrimEnd() $available = $line.Substring($availableStart, $sourceStart - $availableStart).TrimEnd() $software = [Software]::new() $software.Name = $name; $software.Id = $id; $software.Version = $version $software.AvailableVersion = $available; $upgradeList += $software } } $upgradeList | Format-Table $toSkip = @( 'Microsoft.EdgeWebView2Runtime', 'Microsoft.Edge', "Microsoft.OneDrive") foreach ($package in $upgradeList) { if (-not ($toSkip -contains $package.Id)) { Write-Host "Going to upgrade package $($package.id)" & winget upgrade $package.id } else { Write-Host "Skipped upgrade to package $($package.id)" } }[/CODE] Edit the colored exclusion entries to fit your needs. Also, you may want to consider creating a bat file, like the one below. That way the execution policy of powershell scripts will not be a problem. Change "scriptlocationandname" in the example below to the location and given name of the above powershell script. [CODE]@echo off powershell.exe -ExecutionPolicy Unrestricted -Command ". 'C:\scriptlocationandname.ps1'" TIMEOUT /T 5[/CODE] Anyways, that's it. I hope you find it useful. [/QUOTE]
Insert quotes…
Verification
Post reply
Top