PSSnow
PSSnow copied to clipboard
Invoke-SNOWWebRequest - Parameter error in PowerShell Core 7.3.x
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)
- Import-Module PSSnow
- Set-SNOWAuth -Instance "dev123456" -Credential (get-credential)
- Get-SNOWUser -limit 5 -offset 5
- 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.