In case this error occurs in the context of Azure Devops on a self-hosted runner, it is most likely due to the runner being run in a Powershell Core command line.
Using the suggested workarounds or running it in a Windows Powershell instead should fix the issue.