PowerShell Logo Small

New-Object



This is the built-in help made by Microsoft for the command 'New-Object', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Creates an instance of a Microsoft .NET Framework or COM object.

SYNTAX


New-Object -ComObject <string> [-Strict] [-Property <hashtable>] [<CommonParameters>]
New-Object [-TypeName] <string> [[-ArgumentList] <Object[]>] [-Property <hashtable>] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The New-Object cmdlet creates an instance of a .NET Framework or COM object.

You can specify either the type of a .NET Framework class or a ProgID of a COM object. By default, you type the fully qualified name of a .NET Fr
amework class and the cmdlet returns a reference to an instance of that class. To create an instance of a COM object, use the ComObject parameter
and specify the ProgID of the object as its value.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkID=113355
Compare-Object
Select-Object
Sort-Object
ForEach-Object
Group-Object
Measure-Object
Tee-Object
Where-Object

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

C:\PS>new-object -typename System.Version -argumentlist "1.2.3.4"

Major Minor Build Revision
----- ----- ----- --------
1 2 3 4



Description
-----------
This command creates a System.Version object using the string "1.2.3.4" as the constructor.








-------------------------- EXAMPLE 2 --------------------------

C:\PS>$ie = new-object -comobject InternetExplorer.Application -property @{navigate2="www.microsoft.com"; visible = $true}



Description
-----------
This command creates an instance of the COM object that represents the Internet Explorer application. It uses the Property parameter to call the
Navigate2 method and to set the Visible property of the object to $true to make the application visible.

This command is the equivalent of the following:

$ie = new-object -comobject InternetExplorer.Application
$ie.navigate2("www.microsoft.com")
$ie.visible = $true








-------------------------- EXAMPLE 3 --------------------------

C:\PS>$a=new-object -comobject Word.Application -strict -property @{visible=$true}

New-Object : The object written to the pipeline is an instance of the type
"Microsoft.Office.Interop.Word.ApplicationClass" from the component's prima
ry interop assembly. If this type exposes different members than the IDispa
tch members, scripts written to work with this object might not work if the
primary interop assembly is not installed.
At line:1 char:14
+ $a=New-Object <<<< -COM Word.Application -Strict; $a.visible=$true



Description
-----------
This command demonstrates that specifying the Strict parameter causes the New-Object cmdlet to generate a non-terminating error when the COM obje
ct that is created uses an interop assembly.








-------------------------- EXAMPLE 4 --------------------------

C:\PS>$objshell = new-object -comobject "Shell.Application"

C:\PS> $objshell | get-member

C:\PS> $objshell.ToggleDesktop()



Description
-----------
The command uses the ComObject parameter to create a COM object with the "Shell.Application" ProgID. It stores the resulting object in the $objSh
ell variable.

The second command pipes the $objShell variable to the Get-Member cmdlet, which displays the properties and methods of the COM object.

The third command calls the ToggleDesktop method of the object to minimize the open windows on your desktop.