【发布时间】:2014-02-07 07:58:17
【问题描述】:
我尝试将 SharePoint 列表中的数据(日期)与数组(多个日期)中的数据进行比较。如果数组中有一个项目(那么不是真正的数组),它可以工作,但不止一个它会失败。 SharePoint 列表包含一个日期(格式为 M/dd/yyyy),如果我的脚本在该日期后三天内运行,它将执行更多操作,否则会失败。最终,我需要在 60 天后使用它,所以为了保持脚本的可管理性,我想让阵列正常工作。轻松将 60 天保存回数组将是我的下一个挑战。
我希望能够在脚本中使用相对于当天的日期数组。一个固定的日期是行不通的。我正在尝试查看来自 SharePoint 的日期是否在数组中。
$item is an item from the SharePoint list, and the stuff in brackets ["..."] is the column header.
这就是我获取日期的方式:
$today = (get-date).ToString("M/dd/yyyy")
$yesterday = (get-date).AddDays(-1).ToString("M/dd/yyyy")
$twodaysago = (get-date).AddDays(-2).ToString("M/dd/yyyy")
这是我的数组:
enter code here$scheduledate = $today,$yesterday,$twodaysago
这是逻辑:
if(($item["Computer"] -eq "$computer") -and ($item["Status"] -eq "No") -and ($item["Schedule Date"] -contains $scheduledate))
其他尝试:
If $scheduledate is set to this it works:
$scheduledate = $今天
如果 $scheduledate 设置为此它不起作用:$scheduledate = $today,$yesterday,$twodaysago
我什至明确创建了数组,但它不起作用:$scheduledate = @($today,$yesterday,$twodaysago)
引号,空格,都试过了。
我试过这些:
-and ($item["Schedule Date"] -eq $scheduledate)) - works if dates match
-and ($item["Schedule Date"] -contains $scheduledate)) - works with single item in array
-and ($item["Schedule Date"] -match $scheduledate)) - ?
-and ($item["Schedule Date"] -like $scheduledate)) - ?
这可行,但在 60 天内并不理想:if(($item["Computer"] -eq "$computer") -and
($item["Status"] -eq "No") -and `
($item["Schedule Date"] -contains $today) -or ($item["Schedule Date"] -contains $yesterday) -or ($item["Schedule Date"] -contains $twodaysago))
我不确定如何确定 SharePoint 中的数据格式,或者它是否重要。
请帮忙。
【问题讨论】:
标签: arrays date sharepoint powershell