System.Uri does not contain a method named ‘new’

Question:

[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

Answer:

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.

Source:

System.Uri does not contain a method named ‘new’ by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply