Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix passing null parameters to Find-WinGetPackage #2092

Merged
merged 1 commit into from Apr 25, 2022

Conversation

Copy link
Contributor

@bftblomster bftblomster commented Apr 13, 2022


This PR enables all cmdlets in the module and makes Install-WinGetPackage actually work. There may be other stuff wrong with the other cmdlets but I didn't test the other ones thoroughly.

Microsoft Reviewers: Open in CodeFlow

@denelon
Copy link
Contributor

@denelon denelon commented Apr 14, 2022

It looks like I didn't get "--verbose-log" in there. Did I miss something?

@bftblomster
Copy link
Contributor Author

@bftblomster bftblomster commented Apr 14, 2022

It looks like I didn't get "--verbose-log" in there. Did I miss something?

I don't see that in the original version. Maybe it wasn't added?

@denelon
Copy link
Contributor

@denelon denelon commented Apr 14, 2022

That wouldn't surprise me! Would you mind adding it?

@bftblomster
Copy link
Contributor Author

@bftblomster bftblomster commented Apr 15, 2022

That wouldn't surprise me! Would you mind adding it?

From what I can tell is Invoke-WinGetCommand would need to have verbose logging support and I think that's outside my abilities to add.

@denelon
Copy link
Contributor

@denelon denelon commented Apr 15, 2022

No worries then 😊. I'll try to remember to add it after this PR is resolved.

@bftblomster
Copy link
Contributor Author

@bftblomster bftblomster commented Apr 22, 2022

I came up with a function for getting already installed winget packages. I've just tested this on the Visual C++ Redistributables. It gives me the output I need.

function Get-LocalWinGetPackage {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [string]
        $Id
    )
    $Command = "winget list --id $Id --exact --count 1 --source winget"
    $CommandOutputRaw = Invoke-Expression -Command $Command

    $Index = 0
    ForEach ($Line in $CommandOutputRaw) {
        If ($Line -match "^---.") {
            $TitleLine = $CommandOutputRaw.Get($Index - 1)
            $ResultLine = $CommandOutputRaw.Get($Index + 1)
            break
        }
        $Index++
    }
    $Titles = @()
    $TitleLineHeadings = $TitleLine.Split(' ') | Select-String -Pattern "[a-z]"
    ForEach ($TitleHeading in $TitleLineHeadings) {
        $Title = [PSCustomObject]@{
            TitleName = $TitleHeading.ToString()
            TitleStartIndex = $TitleLine.IndexOf($TitleHeading.ToString())
            TitleLength = $TitleHeading.ToString().Length
        }
        $Titles += $Title
    }
    $WinGetPackage = New-Object PSObject
    $Index = 0
    ForEach ($Title in $Titles) {
        If (($Index + 1) -eq $Titles.Count) {
            $ResultLength = $ResultLine.Length - $Titles[$Index].TitleStartIndex
        } Else {
            $ResultLength = $Titles[$Index + 1].TitleStartIndex - $Title.TitleStartIndex
        }
        $VersionTitles = @("Version","Available")
        If ($VersionTitles -contains $Title.TitleName) {
            Add-Member -InputObject $WinGetPackage -MemberType NoteProperty -Name $Title.TitleName -Value ([System.Version]$ResultLine.Substring($Title.TitleStartIndex, $ResultLength).Trim())
        } Else {
            Add-Member -InputObject $WinGetPackage -MemberType NoteProperty -Name $Title.TitleName -Value $ResultLine.Substring($Title.TitleStartIndex, $ResultLength).Trim()
        }
        $Index++
    }
    return $WinGetPackage
}

@denelon denelon merged commit 2937bdf into microsoft:master Apr 25, 2022
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants