public/Get-WinGetWrapperUpgradeList.ps1
function Get-WinGetWrapperUpgradeableList { <# .SYNOPSIS Gets winget upgrade list .EXAMPLE Get-WinGetWrapperUpgradeableList This example retrieves all software identified by winget .LINK ConvertFrom-FixedColumnTable Test-VSCode Test-IsISE #> [CmdletBinding()] param( ) $OriginalEncoding = [Console]::OutputEncoding If(Test-VSCode -eq $false -and Test-IsISE -eq $false){ [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new() } # filter out progress-display and header-separator lines $List = (winget upgrade --accept-source-agreements) -match '^\p{L}' | ConvertFrom-FixedColumnTable $NewList = @() Foreach($Item in $List){ #some items that output using winget have shortened names and id displayed in console window due to unicode output. #first attempt to expand id by using the name with a winget command that has less data output If( ($Item.Id).Length -gt 44 ){ Write-Verbose ("Expanding app Id: {0}" -f $Item.Id) $Expanded = ((winget list --name $Item.Name) -split '`n'| Select -Last 3 | ConvertFrom-FixedColumnTable) $ExpandedMatch = $Expanded | Where Name -eq $Item.Name $Item.Name = $Expanded.Name -replace '\P{IsBasicLatin}'.Trim() $Item.Id = $Expanded.Id -replace '\P{IsBasicLatin}'.Trim() } #if id expanasion doesn't expand name as well, attempt that by using hte already expanded Id If( ($Item.Name).Length -gt 44 ){ Write-Verbose ("Expanding app Name: {0}" -f $Item.Name) $Expanded = ((winget list --id $Item.Id --exact) -split '`n'| Select -Last 3 | ConvertFrom-FixedColumnTable) $Item.Name = $Expanded.Name #-replace '-\P{IsBasicLatin}'.Trim() }Else{ $Item.Name = $Item.Name -replace '\P{IsBasicLatin}'.Trim() } #collect item to list $NewList += $Item } #restore encoding settings If(Test-VSCode -eq $false -and Test-IsISE -eq $false){ [Console]::OutputEncoding = $OriginalEncoding } Return $NewList } |