Showing posts with label Powershell. Show all posts
Showing posts with label Powershell. Show all posts

28 Oct 2011

Sending email using GMail account in powershell


This is an example code to send an email using GMail account in Powershell.

"border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;">
            #send email            
            $smtpServer = "smtp.gmail.com"
            $smtp = new-object Net.Mail.SmtpClient($smtpServer, 587)
            $smtp.EnableSsl = $true
            $smtp.Credentials = new-object System.Net.NetworkCredential("","");
            $smtp.Send($fromAddr, $toAddr, $subject, $body)
            "Email Sent"

5 Sept 2011

Creating FTP directory using Powershell


This code below can be used when you want to create  a directory in FTP server.

$makeDirectory = [System.Net.WebRequest]::Create();
$makeDirectory.Credentials = New-Object System.Net.NetworkCredential(,)
$makeDirectory.Method = [System.Net.WebRequestMethods+FTP]::MakeDirectory;
$makeDirectory.GetResponse();

1 Sept 2011


This is an example of powershell script function that changes image format and size.
I've just updated the code from internet and using this on my powershell project.
$image is the file path of image file.


[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
function Convert-Image{
    param($image,$toFormat,$saveTo,$smalldim,$bigdim)
 
    $baseName = [System.IO.Path]::GetFileNameWithoutExtension($image)
    $img = [System.Drawing.Image]::FromFile($image)
 
    "$image"
    if ($img.Width -gt $img.Height) {
        $width = $bigdim
        $height = $smalldim
    } else {
        $width = $smalldim
        $height = $bigdim
    }
 
    $ResizedImage = New-Object System.Drawing.Bitmap @($width, $height)
    $graphics = [System.Drawing.Graphics]::FromImage($ResizedImage)
    $graphics.DrawImage($img, 0, 0, $Width, $Height)
    $graphics.Dispose()
    $ResizedImage.save("$saveTo\$baseName.$toFormat",$toFormat)
}