I have an enterprise wiki site collection inside my sharepoint server 2013 on-premises. now i want to write a powershell script, which will send an email mentioning all the wiki pages that have been modified after a specifc date.
so i wrote the following:-
$startdate = (Get-Date 2017-12-19)
$emailbody =""
$web = Get-SPWeb "http://*****/kb/wiki/"
$list = $web.GetList(($web.ServerRelativeUrl.TrimEnd("/") + "/Pages"))
foreach ($item in $list.items)
{
if ($item["modified"] -ge $startdate )
{
$emailbody = $emailbody + "<br/>" +$item["Title"].toString()
}
}
Write-Host "Sending Email"
#SMTP server name
$smtpServer = "****"
#Creating a Mail object
$msg = new-object Net.Mail.MailMessage
#Creating SMTP server object
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
#Email structure
$msg.From = "****@******"
#$msg.ReplyTo = "***@****"
$msg.To.Add("****@*****")
$msg.subject = "My Subject"
$msg.body = "Hi , <br/>"+ "The following wiki pages have been modifed since 19/12/2017 <br/>"
$msg.IsBodyHTML=$true
#Sending email
$smtp.Send($msg)
Now currently the problem is that the following check if ($item["modified"] -ge $startdate )
will always return false. Even i have wiki pages which were modified after 19/12/2017.. so can anyone advice on this please?
second question. is there a way to allow specifying the hours:minutes:seconds beside the day/month/year?
(get-date -format d -date 2017-12-19)
i will get the following19/12/2017
and i have a wiki page which have the following last modified date20/12/2017 11:56 AM
but the if statementif ($item["modified"] -ge $startdate )
will be false$CultureDateTimeFormat = (Get-Culture).DateTimeFormat $DateFormat = $CultureDateTimeFormat.ShortDatePattern $TimeFormat = $CultureDateTimeFormat.LongTimePattern $DateTimeFormat = "$DateFormat $TimeFormat" $DateTime = [DateTime]::ParseExact("19/12/2017 3:14:03 PM",$DateTimeFormat, System.Globalization.DateTimeFormatInfo]::InvariantInfo,[System.Globalization.DateTimeStyles]::None)