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?