PSSnow icon indicating copy to clipboard operation
PSSnow copied to clipboard

Invoke-SNOWWebRequest - Parameter error in PowerShell Core 7.3.x

Open ad-85 opened this issue 9 months ago • 1 comments

Describe the bug When calling Invoke-SNOWWebRequest in PS Core 7.3.x, a ParameterBindingException is thrown. This is because the following code is used to determine which parameter name to use (due to the breaking change in PS Core version 7.4.0)

To Reproduce Steps to reproduce the behavior:

(will only throw the error in PS 7.3.x)

  1. Import-Module PSSnow
  2. Set-SNOWAuth -Instance "dev123456" -Credential (get-credential)
  3. Get-SNOWUser -limit 5 -offset 5
  4. See error as per below:
Invoke-WebRequest:
Line |
1405 |  … Invoke-WebRequest @PSBoundParameters @ProxyAuth @TimeoutSplat -UseBas …
     |                                                    ~~~~~~~~~~~~~
     | A parameter cannot be found that matches parameter name 'OperationTimeoutSeconds'.

PS C:\Users\[username]> $PSVersionTable.PSVersion

PS C:\Users\[username]> (Get-Command "Invoke-WebRequest" | Select -Expand Parameters).Keys -match 'TimeoutSec'
TimeoutSec
PS C:\Users\[username]> 'TimeoutSec' -in (Get-Command "Invoke-WebRequest" | Select -Expand Parameters).Keys
True
PS C:\Users\[username]> 'OperationTimeoutSeconds' -in (Get-Command "Invoke-WebRequest" | Select -Expand Parameters).Keys
False

Major  Minor  Patch  PreReleaseLabel BuildLabel
-----  -----  -----  --------------- ----------
7      3      4

Expected behavior The cmdlet should default to using TimeoutSec which is still present in 7.3. The below adjustment to the boolean check will resolve it:

Old:

PS C:\Users\[username]> $PSVersionTable.PSVersion.ToString() -gt 7.3
True

New:

PS C:\Users\[username]> $PSVersionTable.PSVersion.ToString() -ge 7.4
False

Environment (please complete the following information):

  • Module Version: 1.3.1
  • Powershell Version: 7.3.4
  • OS: Windows Server 2019
  • Servicenow Version: Vancouver

Additional context Add any other context about the problem here.

ad-85 avatar May 17 '24 18:05 ad-85