Reputation: 1251
I'm making a script that collect two dates from the system. One from when the scheduling task has last run and the date a list has last been modified. Problem is that the datetime format isn't correct .
What I want to do is to check if the list has been changed since the last time the scheduling task has run.
$scheduledTask = Get-ScheduledTask -TaskName "SharePoint scheduling" | Get-ScheduledTaskInfo
$scheduledTaskLastRunTime = $scheduledTask.LastRunTime
$listExist = $spSourceWeb.Lists | where{$_.Title -eq $listName}
if($listExist)
{
$spSourceList = $spSourceWeb.Lists[$listName]
if ($scheduledTaskLastRunTime -le $spSourceList.LastItemModifiedDate)
{
Write-Host " Changes found" -ForegroundColor Green
SetListColumnToCopy($listName)
}
Do I do the IF correct ? What magic do I have to do to check the datetime? I've read that "don't need a special format to compare dates in Powershell" but is it true in this situation?
Upvotes: 2
Views: 624
Reputation: 72640
You should use ParseExact
static method from DateTime class.
$dateToCompare = [datetime]::ParseExact("09.04.2015 10:50:03","MM.dd.yyyy hh:mm:ss", $null)
Upvotes: 2