Contact Info

Crumbtrail » Administration » Powershell » Powershell 1.0 » New-Object

New-Object - Powershell 1.0 CmdLet

Microsoft Windows PowerShell is a command-line shell and scripting tool based on the Microsoft .NET Framework. It is designed for system administrators, engineers and developers to control and automate the administration of Windows and applications.

More than hundred command-line tools (so called "cmdlets") can be used to perform system administration tasks and Windows Management Instrumentation (WMI). These cmdlets are easy to use, with standard naming conventions and common parameters, and standard tools for piping, sorting, filtering, and formatting data and objects.


Create a new .Net object


typeName string
       The fully-qualified name of the .Net class. 

   -argumentList Object
       A comma separated list of arguments to pass to the constructor of the .Net class.

   -comObject string
       Programmatic Identifier (ProgID) of the COM object.

       Raise an error if the COM object that you attempt to
       create uses an interop assembly.
       This enables you to distinguish actual COM objects from
       .Net objects with COM-callable wrappers.
       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutVariable.

Create a COM object "Shell.Application" and store the resulting reference in a variable, display the properties and methods of the COM object (via get-member.) Then use the ToggleDesktop method to minimizes all open desktop windows:

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

Create a COM object "Word.Application" and store the resulting reference in a variable:

PS C:\>$myWord=new-object -comobject Word.Application

Send email:

# Instantiate an SmtpClient object
$SMTP_Mail = new-object Net.Mail.SmtpClient -arg ""

# Instantiate a new MailMessage object, with sender, destination,subject and body
$Message = new-object Net.Mail.MailMessage("","", "Subject", "Here is some email")

# Add an attachment to the message
$Attach = new-object Net.Mail.Attachment("c:\\demo.txt")

# Send the mail

For more examples, type: "get-help New-Object -detailed"