Contact Info

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

New-Object - Powershell 1.0 CmdLet

ActiveXperts Network Monitor ships with integrated Powershell scripts to monitor complex network. The scripts run out of the box
Download the ActiveXperts Network Monitor FREE version now »


Create a new .Net object

New-Object [-typeName] string[] [[-argumentList] Object[]]

      New-Object [-comObject] string[] [-strict] 

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"