Posts Tagged .NET

Recursive Listing of Files by Date


Using powershell to recursively list files modified before or after a certain date is an easy one line powershell script.

1
get-childitem -Recurse |where {$_.lastwritetime -gt (date).adddays(-10)}

or to list by a certain date:

1
 get-childitem -Recurse |where {$_.lastwritetime -gt "10/2/09"}

,

No Comments

Windows 7 Powershell Pack


The Windows 7 Powershell Pack has been released by Microsoft. A brief feature list as well as the download can be found at the following link:

Windows 7 Resource Kit Powershell Pack

, ,

No Comments

Change File Modified Date

Using Powewrshell Set_LastWriteTime, we are able to modify a files last modifed date and time.

1
2
$date = date
(get-item c:\temp\list.txt).set_LastWriteTime($date)

To adjust the date to a day in the past just change the $date line:

1
2
$date = (date).AddDays(-10)
(get-item c:\temp\list.txt).set_LastWriteTime($date)

This just moved the date back 10 days from today. To go forward you would do:

1
2
$date = (date).AddDays(10)
(get-item c:\temp\list.txt).set_LastWriteTime($date)

,

No Comments

Setting SMTP Message Priority in Powershell


To expand on my previous post regarding how to send email from Powershell, below is an example that includes forcing plain text (or html), setting mesage priority, setting notification options, as well as adding CC: and BCC:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Setting SMTP Priority using Powershell V1
# Yattaa.com 10/07/2009
#
$email = New-Object System.Net.Mail.MailMessage
$email.From = "user@yourdomain.com"
$email.To.Add("user@yourdomain.com")
$email.To.Add("user@yourdomain.com")
$email.CC.Add("user@yourdomain.com")
$email.BCC.Add("user@yourdomain.com")
$email.DeliveryNotificationOptions = [System.Net.Mail.DeliveryNotificationOptions]::OnSuccess
$email.IsBodyHtml = $false
$email.Priority = [System.Net.Mail.MailPriority]::High
$email.Subject = "Subect Here"
$email.Body = "Body Here"
$smtp = New-Object System.Net.Mail.SmtpClient
$smtp.Host = "SMTP Server Here"
$smtp.Send($email)

, ,

No Comments

sending email in powershell

Version 1:

$emailFrom = “user@domain.com”
$emailTo = “user@domain.com”
$subject = “subject”
$body = “body”
$smtpServer = “smtp server”
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)

Version 2:

PS C:\Windows\system32> get-help send-mailmessage

NAME
    Send-MailMessage

SYNOPSIS
    Sends an e-mail message.
SYNTAX
    Send-MailMessage [-To] <string[]> [-Subject] <string> -From <string> [[-Body] <string>] [[-SmtpServer] <string>] [-Attachments <string[]>] [-Bcc <string[]>] [-BodyAsHtml] [-Cc <string[]>] [-Credential <PSCredential>] [-DeliveryNotificationOption {None | OnSuccess | OnFailure | Delay | Never}] [-Encoding <Encoding>] [-Priority {Normal | Low | High}] [-UseSsl] [<CommonParameters>]
DESCRIPTION
    The Send-MailMessage cmdlet sends an e-mail message from within Windows PowerShell.
RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=135256

REMARKS
    To see the examples, type: “get-help Send-MailMessage -examples”.
    For more information, type: “get-help Send-MailMessage -detailed”.
    For technical information, type: “get-help Send-MailMessage -full”.

, ,

No Comments