I'm having issues with this powershell script below. It does work with SP 2007 but won't work with Sp 2010. My goal as you can see is to filter the list returned using the field Date - 1.
But getting the error:
You cannot call a method on a null-valued expression.
At C:\Users\AppData\Local\Temp\2\e70c0e06-6e66-4318-8480-952ccae0460e.ps1:31 char:20 + $col=$list.GetItems <<<< ($query)[0] + CategoryInfo : InvalidOperation: (GetItems:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
function Daily()
{
[System.reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[System.Reflection.Assembly]::LoadWithPartialName("System.web")
$site = new-object Microsoft.SharePoint.SPSite("http://mysites/sites/Intranet/")
#$web = $site.OpenWeb()
$web=$site.rootWeb
$list = $web.Lists["Communications"]
#$today = (Get-Date).AddDays(-1).ToString("yyyy-MM-dd")
$today = (Get-Date).ToString("yyyy-MM-dd")
$caml = '<Where>
<Eq>
<FieldRef Name="Date"/>
<Value Type="DateTime">
{0}
</Value>
</Eq>
</Where>
' -f $today
$query=new-object Microsoft.SharePoint.SPQuery
$query.Query=$caml
$col=$list.GetItems($query)[0]
$Results = @()
foreach ($r in $col) {
$Title = "<b style='font-family:Calibri;'>" + $r.Title + "</b>"
$Description = "<span style='font-family:Calibri;'>" + $r.Body + "</span>"
$LinkToitemID = "http://Commus/DispForm.aspx?ID=" + $r.ID
$scommsLink = "<a href=$LinkToitemID style='font-family:Calibri;'> read </a>"
$concResult = "" + "<br><br><b style='color:#0054A4;font-size:17px;font-weight:bold'>" + $Title + "</b><br/><br/>" + $Description + "<br>" + $scommsLink + "<br><hr>"
$Results += $concResult
}
$web.Dispose()
$site.Dispose()
write-host $Results
}