PowerShell Logo Small


This is the built-in help made by Microsoft for the command 'New-Object', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' 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.


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


New-Object [-TypeName] <String> [[-ArgumentList] [<Object[]>]] [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}] [-InformationVariable
[<System.String>]] [-Property [<IDictionary>]] [<CommonParameters>]
New-Object [-ComObject] <String> [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]] [-Property
[<IDictionary>]] [-Strict] [<CommonParameters>]

Search powershellhelp.space


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 Framework 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.



Online Version: http://go.microsoft.com/fwlink/p/?linkid=293993




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

PS C:\>New-Object -TypeName System.Version -ArgumentList ""
Major Minor Build Revision

----- ----- ----- --------

1 2 3 4

This command creates a System.Version object. It uses a "" string as the constructor.

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

PS C:\>$ie = New-Object -COMObject InternetExplorer.Application -Property @{Navigate2="www.microsoft.com"; Visible = $true}

This command creates an instance of the COM object that represents the Internet Explorer application. The value of the Property parameter is a hash table that calls the
Navigate2 method and sets 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.Visible = $true

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

PS C:\>$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 primary
interop assembly. If this type exposes different members than the IDispatch
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

This example demonstrates that adding the Strict parameter causes the New-Object cmdlet to generate a non-terminating error when the COM object uses an interop assembly.

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

The first command uses the ComObject parameter of the New-Object cmdlet to create a COM object with the "Shell.Application" ProgID. It stores the resulting object in the
$objShell variable.
PS C:\>$objshell = New-Object -COMObject "Shell.Application"

The second command pipes the $objShell variable to the Get-Member cmdlet, which displays the properties and methods of the COM object. Among the methods is the ToggleDesktop
PS C:\>$objshell | Get-Member
TypeName: System.__ComObject#{866738b9-6cf2-4de8-8767-f794ebe74f4e}

Name MemberType Definition

---- ---------- ----------

AddToRecent Method void AddToRecent (Variant, string)

BrowseForFolder Method Folder BrowseForFolder (int, string, int, Variant)

CanStartStopService Method Variant CanStartStopService (string)

CascadeWindows Method void CascadeWindows ()

ControlPanelItem Method void ControlPanelItem (string)

EjectPC Method void EjectPC ()

Explore Method void Explore (Variant)

ExplorerPolicy Method Variant ExplorerPolicy (string)

FileRun Method void FileRun ()

FindComputer Method void FindComputer ()

FindFiles Method void FindFiles ()

FindPrinter Method void FindPrinter (string, string, string)

GetSetting Method bool GetSetting (int)

GetSystemInformation Method Variant GetSystemInformation (string)

Help Method void Help ()

IsRestricted Method int IsRestricted (string, string)

IsServiceRunning Method Variant IsServiceRunning (string)

MinimizeAll Method void MinimizeAll ()

NameSpace Method Folder NameSpace (Variant)

Open Method void Open (Variant)

RefreshMenu Method void RefreshMenu ()

ServiceStart Method Variant ServiceStart (string, Variant)

ServiceStop Method Variant ServiceStop (string, Variant)

SetTime Method void SetTime ()

ShellExecute Method void ShellExecute (string, Variant, Variant, Variant, Variant)

ShowBrowserBar Method Variant ShowBrowserBar (string, Variant)

ShutdownWindows Method void ShutdownWindows ()

Suspend Method void Suspend ()

TileHorizontally Method void TileHorizontally ()

TileVertically Method void TileVertically ()
ToggleDesktop Method void ToggleDesktop ()

TrayProperties Method void TrayProperties ()

UndoMinimizeALL Method void UndoMinimizeALL ()

Windows Method IDispatch Windows ()

WindowsSecurity Method void WindowsSecurity ()

WindowSwitcher Method void WindowSwitcher ()

Application Property IDispatch Application () {get}

Parent Property IDispatch Parent () {get}

The third command calls the ToggleDesktop method of the object to minimize the open windows on your desktop.
PS C:\>$objshell.ToggleDesktop()

This example shows how to create and use a COM object to manage your Windows desktop.