'Why isn't -OutputAs parameter of Invoke-Sqlcmd valid?

I'm getting this error in my powershell script:

Invoke-Sqlcmd : A parameter cannot be found that matches parameter name 'OutputAs'.
At powershell_script_name.ps1:317 char:97
+ ... nce $strSserver -Database $strDatabase -Query $query -OutputAs Datatab ...
+ CategoryInfo : InvalidArgument (:) [Invoke-Sqllcmd], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound, MicrosoftSqlserver.Management.PowerShell.GetScriptCommand
  • SqlServer module version: 21.1.18256
  • Powershell version: 5.1.14393.4583
  • [Environment]::Is64BitProcess: True
  • SQL Server version: 2016 Developer x64 (13.0.6404.1)
  • OS version: Windows Server 2016 Standard x64

The same code runs on other servers without issues.

P.S. I saw this link, but it refers to an older version of PS: Invoke-Sqlcmd : A parameter cannot be found that matches parameter name 'OutputAs'



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source