Question: looking for a way within a Powershell script to direct which Powershell version to use.
Background:
- Solarwinds system running on a Windows 2019 server (note this is a test "non-prod" system)
- Windows 2019 server comes with Powershell 5.1 by default
- I'm testing a Powershell script monitor which uses Invoke-WebRequest
- For this purpose I need to use the -SkipCertificateCheck switch of Invoke-WebRequest. Note: this switch became available in Powershell 6.x; -SkipCertificateCheck does not exist in Powershell 5.x
- I installed Powershell 7.3 on the server. Note that by default 7.3 will run in tandem with the default 5.1
- Executing from a 7.3 shell my script works as expected and returns data
- However, when I create a script monitor in Solarwinds script does not return any data (note: I run a lot of script monitors in Solarwinds - I know how to set up the message and statistic constructs to return data).
I am still troubleshooting my script in Solarwinds. However, I suspect that the script invokes Powershell 5.1 which will error out on the -SkipCertificateCheck switch.
Does anyone know of a way to direct a script to execute with Powershell 7.x verses 5.x?
Thanks in advance for any input from the community.