Why isn’t “New-Object” aliased to “New”

PowerShell Team

Alistair Young made a Note to Self :

In a standard PowerShell installation, “new” is not an alias for “new-object”. You added that. You should therefore know better that to make this kind of dumbass mistake.

We talked about making “New” an alias to “New-Object” but decided against it in the end because it leaves open the door for us to provide a C#-like NEW keyword sometime in the future. We want PowerShell to provide a nice glide path to C# so in the future, we’d like the following to be equivalent:

$x = New-Object System.DateTime 2007,12,25

$x = new System.DateTime(2007,12,25)

So if we decide to implement this in the future and you’ve aliased New to New-Object, your scripts will break.

 

Jeffrey Snover [MSFT]
Windows PowerShell/MMC Architect
Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

0 comments

Discussion is closed.

Feedback usabilla icon