13.1. Using the new-object Cmdlet
Windows PowerShell allows you to create and manipulate Object Linking and Embedding (OLE) automation compatible COM objects using the new-object cmdlet. The new-object cmdlet also allows you to create new .NET objects. I briefly describe the new-object cmdlet and then go on in this chapter to focus on its usage with COM objects. The aspects of the new-object cmdlet that are relevant to creating .NET objects are described in Chapter 14.
The new-object cmdlet can take the following parameters in addition to supporting the common parameters (which are described in Chapter 6):
TypeName — The fully qualified name of the .NET type of the object that is to be created. A positional parameter used in position 1.
Arguments — Arguments to the constructor of the type specified using the TypeName parameter. The Arguments parameter is optional. When present it is a positional parameter in position 2.
ComObject — Used when creating a new COM object.
Strict — Used with the -ComObject parameter. Specifies that an error should be raised if the cmdlet attempts to access an interop assembly. This allows differentiation between a true COM object and a .NET object with a wrapper.
The TypeName and Arguments parameters are used in connection with creating new .NET objects. Those parameters are described in detail in Chapter 14.
To create a new COM object, use the new-object cmdlet in the following form:
$myCOMObject = new-object -comobject NameOfCOMType
or, if you want ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access