0

I have following PS script;

Resolve-Path HKLM:\SOFTWARE\Microsoft\MSBuild\ToolsVersions\* | Sort-Object PSChildName -Descending | Get-ItemProperty -Name MSBuildToolsPath

PSChildName is a property which holds installed msbuild tools version in my PC. I am trying to sort by tools version desc (14.0 should be on the top). It gives following unexpected output;

MSBuildToolsPath : C:\windows\Microsoft.NET\Framework64\v3.5\ 
PSPath   : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\3.5 
PSParentPath     : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions 
PSChildName      : 3.5 
PSDrive          : HKLM 
PSProvider       : Microsoft.PowerShell.Core\Registry

MSBuildToolsPath : C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ 
PSPath           : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0 
PSParentPath     : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions 
PSChildName      : 4.0 
PSDrive          : HKLM 
PSProvider       : Microsoft.PowerShell.Core\Registry

MSBuildToolsPath : C:\Program Files (x86)\MSBuild\14.0\bin\amd64\ 
PSPath           : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\14.0 
PSParentPath     : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions 
PSChildName      : 14.0 
PSDrive          : HKLM 
PSProvider       : Microsoft.PowerShell.Core\Registry

MSBuildToolsPath : C:\windows\Microsoft.NET\Framework64\v2.0.50727\ 
PSPath           : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\2.0 
PSParentPath     : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions 
PSChildName      : 2.0 
PSDrive          : HKLM 
PSProvider       : Microsoft.PowerShell.Core\Registry

as you can see it is not sorted desc as expected. I am trying to get 14.0 on the top.

How can I achieve that?

Matt
  • 45,022
  • 8
  • 78
  • 119
Teoman shipahi
  • 47,454
  • 15
  • 134
  • 158
  • 1
    See [Sort-Object by greatest numerical value value from Import-CSV](//stackoverflow.com/q/27827398): `gci HKLM:\SOFTWARE\Microsoft\MSBuild\ToolsVersions\* | sort {[float]$_.PSChildName} -Descending | gp -Name MSBuildToolsPath` – wOxxOm Feb 28 '17 at 20:31
  • @wOxxOm I think the issue is also that PSChildName is not a property returned by `resolve-path`. I think what you have will change nothing since that will sort on nulls.. – Matt Feb 28 '17 at 20:32
  • @wOxxOm that fixed my problem, thanks! – Teoman shipahi Feb 28 '17 at 20:37

0 Answers0