2

I want to get the start date and the Due date for a task which will be repeated Annually using Powershell Please.

1 Answer 1

2

The solution is :

$today= Get-Date
$dueDate = (get-date).AddYears(1)

if ($today.DayOfWeek -eq "Monday" -and  $today.Day -le "7" -and  $today.Month -eq "1")
{
    foreach($item1 in $listSource1.Items | Where {$_["Frequency"] -eq "Annually"})
    { 
        $newItem = $listTarget.Items.Add();

        $newItem["StartDate"] = $today.ToShortDateString()
        $newItem["DueDate"] = $dueDate.ToShortDateString()
        newItem.Update()
    }
}
2
  • Great solution @Jihen Commented Sep 4, 2018 at 0:09
  • Thnx Mohamed :)
    – Jihen
    Commented Sep 4, 2018 at 8:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.