cls
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
$sourceWebURL = "xxxxxxxxxxxxxxxxx"
$sourceListName = "xxxxxxxxxxxxxx"
$spSourceWeb = Get-SPWeb $sourceWebURL
$spSourceList = $spSourceWeb.Lists[$sourceListName]
$StartDate=(GET-DATE -format d)
$spSourceItems = $spSourceList.GetItems()
$spSourceItems | ForEach-Object {
$EndDate=$_['Requirement Due Date m/d/y']
$diff=NEW-TIMESPAN –Start $StartDate –End $EndDate
write-host $diff
}
Hi There below is the error from my powershell script and below that is the actual powershell script. I am new to powershell - and I know I am doing something obvious and silly - any help would be appreciated.
All its supposed to do is read a column from a sharepoint list that is of the date format and compare it with todays date - if the diff is 0 do something - otherwise do something else - however - I keep getting the error
72.00:00:00 10052.00:00:00 10052.00:00:00 10052.00:00:00 10052.00:00:00 10052.00:00:00 8402.00:00:00 34.00:00:00 8163.00:00:00 -94.00:00:00 8402.00:00:00 388.00:00:00 8801.00:00:00 10619.00:00:00 8886.00:00:00 8887.00:00:00 415.00:00:00 8481.00:00:00 New-TimeSpan : Cannot bind parameter 'End' to the target. Exception setting "End": "Object reference not set to an instance of an object." At line:16 char:42 + $diff=NEW-TIMESPAN –Start $StartDate –End <<<< $EndDate + CategoryInfo : WriteError: (:) [New-TimeSpan], ParameterBindingException + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.NewTimeSpanCommand
8481.00:00:00 New-TimeSpan : Cannot bind parameter 'End' to the target. Exception setting "End": "Object reference not set to an instance of an object." At line:16 char:42 + $diff=NEW-TIMESPAN –Start $StartDate –End <<<< $EndDate + CategoryInfo : WriteError: (:) [New-TimeSpan], ParameterBindingException + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.NewTimeSpanCommand
8481.00:00:00 302.00:00:00 3589.00:00:00 272.00:00:00 9067.00:00:00 302.00:00:00