Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

PowerShell and SharePoint - comparing data from an array

$
0
0
I have data ( a date) in a SharePoint list that I am trying to compare to data in an array (multiple dates).  If the array has one item in it, it works, more than one it fails.  The SharePoint list contains a date (format of M/dd/yyyy), if my script is run within three days from that date it will do some more things, otherwise fail.  Eventually I need to have it at sixty days back, so to keep the script manageable I'd like to get the array working.  Easily saving sixty days back to an array will be my next challenge.

My hope was that I would be able to have an array of dates, relative to the current day, to use in the script.  A set hard date will not work.  I am trying to see if the date from SharePoint is in the array.

$item is from the SharePoint list, and the stuff in brackets ["..."] is the column header.

This is how I am getting the days:

$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")

This is my array:
$scheduledate = $today,$yesterday,$twodaysago

This is the logic:

if(($item["Computer"] -eq "$computer") -and ($item["Status"] -eq "No") -and ($item["Schedule Date"] -contains $scheduledate))

Other attempts:

If $scheduledate is set to this it works:  $scheduledate = $today

If $scheduledate is set to this it does not work:  $scheduledate = $today,$yesterday,$twodaysago

I have even created the array explicitly, it does not work:  $scheduledate = @($today,$yesterday,$twodaysago)

Quotes, spaces, have been tried.

I have tried these:

-and ($item["Schedule Date"] -eq $scheduledate)) - ?

-and ($item["Schedule Date"] -contains $scheduledate)) - works with single item in array

-and ($item["Schedule Date"] -match $scheduledate)) - ?

-and ($item["Schedule Date"] -like $scheduledate)) - ?

This works, but is not ideal for sixty days:  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))

I'm not sure how to figure out what the format the data in SharePoint is, or if it even matters.  

Please help.




Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>