Contact Info

Crumbtrail

ActiveXperts.com » 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 »

New-Object

Description
Create a new .Net object

Usage


Options


Example(s)
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
$objshell.ToggleDesktop()

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

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

Send email:

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

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

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

# Send the mail
$SMTP_Mail.Send($Message)

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