Skip to content

Commit

Permalink
new winget wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ninmonkey committed Dec 5, 2023
1 parent 3ff0fdb commit b56000e
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions Pwsh/Native.Command/WingetFunctions-TestIfExistingApps.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
function WinGet.GetList {
<#
.SYNOPSIS
gets the list of all currently installed apps, exports as json
#>
param(
# [Parameter()]$x
[switch]$IncludeVersion,
[string]$ExportPath = 'g:\temp\winget.export.json',
[switch]$OpenLogs,
[switch]$EnableInteractive,
[switch]$VerboseLogs,
[switch]$Wait,
[switch]$Cached
)
$WingetArgs = @(
'export'
'-o'
$ExportPath
if( $IncludeVersion ) { '--include-versions' }
if( $OpenLogs ) { '--open-logs' }
if( -not $EnableInteractive ) { '--disable-interactivity' }
if( $VerboseLogs ) { '--verbose-logs' }
if( $Wait ) { '--wait' }

)
if( -not $Cached ) {
winget @wingetArgs
}
"wrote: '$ExportPath'" | write-host
}

function ListApps {
<#
.SYNOPSIS
List apps. defaults to using a cached list, use force to override
#>
param(
[string]$Path = 'g:\temp\winget.export.json',
# Do you want to force the reload?
[switch]$ForceLoad
)
if( $ForceLoad ) {
WinGet.GetList -ExportPath $Path -Cached:$false
}
$data = get-content 'g:\temp\winget.export.json' | ConvertFrom-Json
$rawNames = $Data.Sources.Packages.PackageIdentifier | Sort-Object -Unique
return $rawNames
}

function FindAppsToRemove {
<#
.synopsis
which of the apps that are wanted, are actually installed?
#>
param(
[string[]]$AppsToRemove,
[switch]$ForceLoad
)
$existing = ListApps -ForceLoad:$ForceLoad
$installed = $AppsToRemove | ?{
$curName = $_
$curName -in @( $existing )
}
return $installed
}
# code -g 'g:\temp\winget.export.json'
# code -g 'g:\temp\winget2.json'

$ToRemoveList = @(
'7zip.7zip'
'Microsoft.PowerToys'
'Microsoft.SQLServer2012NativeClient'
'Microsoft.SQLServer2023NativeClient'
)
return

# example use
ListApps
FindAppsToRemove $toRemoveList




WinGet.GetList -IncludeVersion -ExportPath 'g:\temp\winget2.json' -OpenLogs -EnableInteractive -VerboseLogs -Wait

0 comments on commit b56000e

Please sign in to comment.