Coder Social home page Coder Social logo

Comments (4)

megamorf avatar megamorf commented on June 12, 2024 1

I'll check this later today and close the issue if it's fixed.

from poshspec.

michaeltlombardi avatar michaeltlombardi commented on June 12, 2024

Should this issue have been closed by #26? It seems so.

from poshspec.

megamorf avatar megamorf commented on June 12, 2024

Unfortunately this isn't fixed. I think it'd make sense to change the package selection approach:

So instead of this:

Get-Package -Name "$Target" -ErrorAction SilentlyContinue | Select-Object -First 1

do this:

# Requires PSv4 (http://www.powershellmagazine.com/2014/10/22/foreach-and-where-magic-methods/)
(Get-Package -Name "$Target" -ErrorAction SilentlyContinue).Where({$_.Name -eq "$Target"},'First')

IMO Get-Package is to blame since they use an implicit wildcard for the Name attribute:

PS C:\> Get-Package -Name 'Microsoft Visual C++' | Select Name,Version

Name                                                                                               Version
----                                                                                               -------
Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.4148                                     9.0.30729.4148
Microsoft Visual C++ 2010  x64 Redistributable - 10.0.40219                                        10.0.40219
Microsoft Visual C++ 2005 Redistributable (x64)                                                    8.0.61000
Microsoft Visual C++ 2010  x86 Redistributable - 10.0.40219                                        10.0.40219
Microsoft Visual C++ 2013 x86 Minimum Runtime - 12.0.21005                                         12.0.21005
Microsoft Visual C++ 2013 x86 Additional Runtime - 12.0.21005                                      12.0.21005
Microsoft Visual C++ 2013 x64 Additional Runtime - 12.0.21005                                      12.0.21005
Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.6161                                     9.0.30729.6161
Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.6161                                     9.0.30729.6161
Microsoft Visual C++ 2013 x64 Minimum Runtime - 12.0.21005                                         12.0.21005
Microsoft Visual C++ 2005 Redistributable                                                          8.0.61001
[output omitted]

Looking back at my original example where I tell Get-Package to get me a package with the name of Microsoft Visual C++ 2005 Redistributable it does the following which is always going to fail the current workaround with Select-Object -First 1

PS C:\> Get-Package -Name 'Microsoft Visual C++ 2005 Redistributable' | Select Name,Version

Name                                            Version
----                                            -------
Microsoft Visual C++ 2005 Redistributable (x64) 8.0.61000
Microsoft Visual C++ 2005 Redistributable       8.0.61001

from poshspec.

matthewbrandes avatar matthewbrandes commented on June 12, 2024

Looks like this was fixed either by an updated PackageManagement Module or Powershell version as I don't see this issue on Window 10.

In any case it seems like simply sorting by name may fix your example.

PS C:\> Get-Package | where name -like "*C++ 2005*" | select name, version

Name                                            Version
----                                            -------
Microsoft Visual C++ 2005 Redistributable (x64) 8.0.61000
Microsoft Visual C++ 2005 Redistributable       8.0.50727.42
PS C:\> Get-Package | where name -like "*C++ 2005*" | select name, version | sort name

Name                                            Version
----                                            -------
Microsoft Visual C++ 2005 Redistributable       8.0.50727.42
Microsoft Visual C++ 2005 Redistributable (x64) 8.0.61000

from poshspec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.