Book Image

Learning PowerCLI for VMware VSphere

By : Robert van den Nieuwendijk
Book Image

Learning PowerCLI for VMware VSphere

By: Robert van den Nieuwendijk

Overview of this book

Table of Contents (17 chapters)
Learning PowerCLI
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 this section, you will learn more ways to create new objects.

Using the New-Object cmdlet

PowerShell has its own cmdlet for creating 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:

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

New-Object [-ComObject] <String> [-Property <IDictionary>] [-Strict [<SwitchParameter>]] [<CommonParameters>]

Using a hash table to create an object

The easiest way to create a Microsoft .NET Framework object as the output of your PowerCLI scripts is to create a PSObject type object using a hash table. The following example creates an object with two members of member type NoteProperty...