Search code examples
powershellsystem

System.Uri does not contain a method named 'new'


[System.Uri]::new('http://www.stackoverflow.com') is failing with error message

[System.Uri] does not contain a method named 'new'

however I am able to find this method on another box. and runs fine.

How to find if there is difference between System object loaded under PowerShell


Solution

  • You need Powershell 5 or higher to use the .ctor of a .NET class. In older versions of Powershell you'll have to use New-Object to do this.