Creating your own objects

There are several ways to create new objects in PowerCLI. In fact, you have already been creating new objects by using the Select-Object -Property command. In the following section, you will learn more ways to create new objects.

Using the New-Object cmdlet

PowerShell has its own cmdlet to create objects: New-Object. You can use this cmdlet to create a Microsoft .NET Framework or COM object.

The New-Object cmdlet has the following syntax. The first parameter set is for creating a Microsoft .NET Framework object:

New-Object [-TypeName] <String> [[-ArgumentList] <Object[]>]
    [-Property <IDictionary>] [<CommonParameters>]

The -TypeName parameter is required.

The second parameter set is for creating a COM object:

New-Object [-ComObject] ...

Get Learning PowerCLI - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.