Press "Enter" to skip to content

Choosing between Add-Type and New-Object

Patrick Gruenauer contrasts two options in Powershell:

Predefined .NET classes: PowerShell makes certain predefined .NET classes directly available without you having to load them with “Add-Type”.

You can simply use “New-Object, to create instances of these classes. This includes many commonly used classes such as “System.String”, “System.DateTime”, “System.IO.FileInfo”

Read on for a few examples of this, as well as when you would want to use Add-Type instead.