May 2010 - Posts

Fun with PowerShell:Send email

Using PowerShell now you can send email.

You can use Send-Mailmessage Cmdlets to send email. Here a code

send-mailmessage –To recipient@domain –From sender@domain –subject subject        –body “Email Message” –smtpserver yoursmtpserver 

However, if you are in open proxy then you may experience  spamcop . However if you have in premise. Exchange then you can send Email.  In my example i setup local smtp server.

sendemail

serveremail

If your mail server support SSL then you may use –usessl . You may authenticate to your smtp server using –credential switch.

Here is the manuals for Send-MailMessage cmdlets

SYNTAX
    Send-MailMessage [-To] <string[]> [-Subject] <string> -From <string> [[-Body] <string>] [[-SmtpServer] <string>] [-Attachments <string[]>] [-Bcc <string[]>] [-BodyAsHtml] [-Cc <string[]>] [-Credential <PSCredential>] [-DeliveryNot
    ificationOption {None | OnSuccess | OnFailure | Delay | Never}] [-Encoding <Encoding>] [-Priority {Normal | Low | H
    igh}] [-UseSsl] [<CommonParameters>]

DESCRIPTION
    The Send-MailMessage cmdlet sends an e-mail message from within Windows PowerShell.

PARAMETERS
    -Attachments <string[]>
        Specifies the path and file names of files to be attached to the e-mail message. You can use this parameter or
        pipe the paths and file names to Send-MailMessage.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?       true (ByValue)
        Accept wildcard characters?  false

    -Bcc <string[]>
        Specifies the e-mail addresses that receive a copy of the mail but are not listed as recipients of the message.
         Enter names (optional) and the e-mail address, such as "Name <someone@example.com>".

        Required?                    false
        Position?                    named
        Default value                None
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -Body <string>
        Specifies the body (content) of the e-mail message.

        Required?                    false
        Position?                    3
        Default value                None
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -BodyAsHtml [<SwitchParameter>]
        Indicates that the value of the Body parameter contains HTML.

        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -Cc <string[]>
        Specifies the e-mail addresses to which a carbon copy (CC) of the e-mail message is sent. Enter names (optional
        ) and the e-mail address, such as "Name <someone@example.com>".

        Required?                    false
        Position?                    named
        Default value                None
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -Credential <PSCredential>
        Specifies a user account that has permission to perform this action. The default is the current user.

        Type a user name, such as "User01" or "Domain01\User01". Or, enter a PSCredential object, such as one from the
        Get-Credential cmdlet.

        Required?                    false
        Position?                    named
        Default value                Current user
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -DeliveryNotificationOption <DeliveryNotificationOptions>
        Specifies the delivery notification options for the e-mail message. You can specify multiple values. "None" is
        the default value.  The alias for this parameter is "dno".

        The delivery notifications are sent in an e-mail message to the address specified in the value of the To parame
        ter.

        Valid values are:

         -- None: No notification.
         -- OnSuccess: Notify if the delivery is successful.
         -- OnFailure: Notify if the delivery is unsuccessful.
         -- Delay: Notify if the delivery is delayed.
         -- Never: Never notify.

        Required?                    false
        Position?                    named
        Default value                None
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -Encoding <Encoding>
        Specifies the encoding used for the body and subject. Valid values are ASCII, UTF8, UTF7, UTF32, Unicode, BigEn
        dianUnicode, Default, and OEM. ASCII is the default.

        Required?                    false
        Position?                    named
        Default value                ASCII
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -From <string>
        Specifies the address from which the mail is sent. Enter a name (optional) and e-mail address, such as "Name <s
        omeone@example.com>". This parameter is required.

        Required?                    true
        Position?                    named
        Default value                None
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -Priority <MailPriority>
        Specifies the priority of the e-mail message. The valid values for this are Normal, High, and Low. Normal is th
        e default.

        Required?                    false
        Position?                    named
        Default value                Normal.
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -SmtpServer <string>
        Specifies the name of the SMTP server that sends the e-mail message.

        The default value is the value of the $PSEmailServer preference variable. If the preference variable is not set
         and this parameter is omitted, the command fails.

        Required?                    false
        Position?                    4
        Default value                $PSEmailServer
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -Subject <string>
        Specifies the subject of the e-mail message. This parameter is required.

        Required?                    true
        Position?                    2
        Default value                None
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -To <string[]>
        Specifies the addresses to which the mail is sent. Enter names (optional) and the e-mail address, such as "Name
         <someone@example.com>". This parameter is required.

        Required?                    true
        Position?                    1
        Default value                None
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -UseSsl [<SwitchParameter>]
        Uses the Secure Sockets Layer (SSL) protocol to establish a connection to the remote computer to send mail. By
        default, SSL is not used.

        Required?                    false
        Position?                    named
        Default value                False
        Accept pipeline input?       false
        Accept wildcard characters?  false

For Help:

get-help send-mailmessage -full

Posted: 05-08-2010 7:15 AM by gandip with no comments

Configuring Live Writer For TechNetNepal.Net

  For starters in Blogging World, here I present a small tutorials on how configure your Windows Live Writer for TechNetnepal.net ‘s Blogs. Windows Live Writer is one of free service given by Microsoft. You may download the Live Installation from here.

When done with installation of Live Writer, start the live Writer. Windows live writer will present you the following screen.

screen` 

  1. Write the URL of your blog on web address. Put your username and password for the following blogs.Here I have used sample user “blogs”. Press Next.screen2
  2. Now select “Community Server” from the Type of Blog that you are using drop list.Replace the <hostname> into technetnepal.net. This is important or else live writer won’t be able to detect your blogs.screen3
  3. It should see something like this. Now press Next.screen4 screen5
  4. I would recommend to allow theme detection of your Blogs. It comes handy when you doing multiple blogs.screen6
  5. Put your Blog title and you are done with configuring happy Blogging.

Copy can be found on http://blogs.gandip.com.np/?p=24

Posted: 05-04-2010 5:25 AM by gandip with 4 comment(s)

Filed under:

PowerShell (Basics)

Powershell is a administrative engine which is interactive command shell. Its is more of scripting language. It is combination of objects from .NET,COM, and WMI frameworks. Windows PowerShell can be extened with:

  • Providers
  • Cmdlets
  • Scripts,functions,aliases

Cmdlets pronounced Command Lets is light weight used in Windows PowerShell enviroment.

PowerShell Extension:

Administration of Microsoft Product like Exchange 2007 Service Pack 1,SQL 2008 R2, Windows Server 2008 now can be done using PowerShell. An example EMS (Exchange Management Shell) now capable of doing all administration in Exchange Server which GUI may not be able to do so. It is just a extension of PowerShell. PSSnapIn is used.

PowerShell Providers:

Using Providers for PowerShell now one can hover around Registry, File System, Certiuficate Store using PowerShell “drives” PSdrive. PSdrive depends open PowerShell providers.

Using PSdrive:

Get-PSdrive to check the list of all current Powershell drives

image

New-PSdrive to Create new PowerShell Drive

Accessing Registry

Using push-location with appropriate location of registry

push-location HKCU:

this will change the current path to registry (HKEY_Current_User). Like hover in registry you can use get-childitem to look around and cd to change the path.

Objects::

Objects have interfaces that act like handles to get information into and out of the object. In other words, an object can be more than just a set of data. In addition to interfaces and methods, an object can have properties or attributes that describe it.

Following is an example of changing a user interface with a property assignment:

$Host.UI.RawUI.ForegroundColor = "Blue"

Use get-member to get the properties and method of any object.

e.g.

get-date|get-member

Dot operator

Use (.) operator to access member of an object.

To pass value of one command into other use parenthesis () for this purpose.

e.g.

(get-date).day

2

(get-date).dayofweek

Monday

To be Continued…

Posted: 05-03-2010 8:18 PM by gandip with no comments

Filed under: