My 2 cents: I had a similar problem and it came from the usage of Powershell ISE which runs on Powershell 5. SQLServer version 22 and SQLPS were installed and visible. Needed to run a PWSH version 7 where the SQLServer version 22 was installed and the code ran directly. Check where they are running the code from.