1

I was trying to make use of the suggestion from this question Get NuGet.exe version from command-line to use the PowerShell command

nuget help | select -First 1

This works and outputs just the line with the version on, which is exactly what I want. But when I try to use it in automation it's a problem because I get an error code from the command even thought it succeeds.

PS C:\> $PSVERSIONTABLE

Name                           Value
----                           -----
PSVersion                      5.1.16299.637
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.637
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

PS C:\> nuget help | select -First 1
NuGet Version: 4.8.1.5435
PS C:\> $?
False
PS C:\> $LASTEXITCODE
-1

I can't find a reason for the error code in the PowerShell documentation for the select-object command.

Interestingly, the problem is not present in PowerShell Core 6.1

Can anybody shed some light on why I'd be seeing this error code or an alternative for getting the nuget version in PowerShell?

3
  • Possible duplicate of Difference between $? and $LastExitCode in PowerShell Commented Oct 18, 2018 at 8:25
  • 1
    Why not simply use (Get-Command nuget.exe).Version or (Get-Command nuget.exe).FileVersionInfo resp. it's sub properties? Commented Oct 18, 2018 at 8:49
  • Thanks for that suggestion @LotPings, that gives me exactly what I need Commented Oct 18, 2018 at 9:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.