0

Hi I need to build a bat possible power shell on standard windows 10 instance.
I need a programmatic way to set an environment variable with the version string of the latest msodbcsql library at https://packages.microsoft.com/rhel/8/prod/

the current latest version is https://packages.microsoft.com/rhel/8/prod/msodbcsql17-17.8.1.2-1.x86_64.rpm but this changes every couple of months.

I thought of something like the following PSEUDO CODE

set msodbcver=Invoke-WebRequest -Uri  https://packages.microsoft.com/rhel/8/prod/ | grep msodbcsq | sort 

but my windows system cannot find Invoke-WebRequest in either cmd.exe or powershell. Yes I am a unix guy trying to figure out equivilent MS scripting

peter cooke
  • 213
  • 1
  • 8
  • Which version of Windows is this? Invoke-WebRequest has been in Powershell since v3. If you can post the contents of `$PSVersionTable` in the question that might help. Don't bother trying to do this in batch/cmd by the way. Powershell is the way to do it. – Mark Henderson Dec 13 '21 at 04:11

1 Answers1

1

If you are running a modern version of Powershell (v3 or above) you can do this with:

$env:msodbcver = (Invoke-WebRequest -Uri https://packages.microsoft.com/rhel/8/prod/).Links.Href | Select-string msodbcsq | Sort-Object -Descending | Select-Object -First 1
Mark Henderson
  • 68,316
  • 31
  • 175
  • 255