Setting QueryFilterAsString via PowerShell

Oct 18, 2013 at 9:15 PM
Hi All,
Wondering if anyone else has had success setting the QueryFilterAsString from PowerShell. I found a great example showing how to do via console app (http://ilohraphael.wordpress.com/2009/05/12/how-to-programmatically-create-a-new-filteredlookup-field/) and I was successful using that approach but I haven't been able to do it via PowerShell. There is no error. Not sure if it is an issue with Thread.SetData or what. Here's the script.

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

Reflection.Assembly::LoadFile("E:\temp\Dev4Side.SP2010.FilteredLookup.dll")

$calendarListName = "Meetings"
$webUrl = "http://vmd001d003/sites/lm/deploy2" $dt = Get-Date $signUpListName = "TestList" $web=get-spweb $webUrl $webId = $web.ID.ToString()
$calendarList = $web.Lists[$calendarListName]
$calendarListId = $calendarList.id.ToString()
$titleExtendedFldId = $calendarList.Fields["TitleExtended"].Id.ToString()
$list=$web.Lists[$signUpListName]
$newId = [System.Guid]::NewGuid().toString()
$list.Fields.AddFieldAsXml("<Field Type='FilteredLookupField' DisplayName='Meeting$newId' Required='FALSE' EnforceUniqueValues='FALSE' WebId='$webid' List='$calendarListId' ShowField='$titleExtendedFldId' UnlimitedLengthInDocumentLibrary='FALSE' ID='{$newId}' StaticName='Meeting$newId' Name='Meeting$newId' />")
$list.Update()
[Dev4Side.SP2010.FilteredLookup.FilteredLookupField]$fld = [Dev4Side.SP2010.FilteredLookup.FilteredLookupField]$list.Fields["Meeting$newId"]
$fld.QueryFilterAsString = "&lt;OrderBy&gt;&lt;FieldRef Name=&quot;EventDate&quot; /&gt;&lt;/OrderBy&gt;&lt;Where&gt;&lt;And&gt;&lt;Gt&gt;&lt;FieldRef Name=&quot;OpenSeats&quot; /&gt;&lt;Value Type=&quot;Number&quot;&gt;0&lt;/Value&gt;&lt;/Gt&gt;&lt;Geq&gt;&lt;FieldRef Name=&quot;EventDate&quot; /&gt;&lt;Value Type=&quot;DateTime&quot;&gt;&lt;Today /&gt;&lt;/Value&gt;&lt;/Geq&gt;&lt;/And&gt;&lt;/Where&gt;"
$fld.AllowMultipleValues = $false
$fld.IsFilterRecursive = $false
$fld.Update($true)
$list.Update()
$web.Dispose()

Thanks in advance,
Eric Halsey