Posts Tagged .NET
Recursive Listing of Files by Date
Posted by admin in Powershell on October 18, 2009
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"} |
Windows 7 Powershell Pack
Posted by admin in Powershell on October 15, 2009
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:
Change File Modified Date
Posted by admin in Powershell on October 14, 2009
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) |
Setting SMTP Message Priority in Powershell
Posted by admin in Powershell on October 8, 2009
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) |
sending email in powershell
Posted by admin in Powershell on September 21, 2009
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”.