I have a SharePoint
PowerShell
script which gets items from a list.
I am changing the CAML
query for different output.
However, upon changing or removing the CAML
query, the method of list.GetItems()
returned 0
result and I have no clue why it is so.
Below is my code snippet:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Set config variables
$baseUrl="http://test.com/"
$listName ="Lists/FilePlan"
#Get Web and List Objects
$web = Get-SPWeb $baseUrl
$list = $web.GetList($listName)
#Define the CAML Query
$queryOriginal = New-Object Microsoft.SharePoint.SPQuery
$queryOriginal.Query = "@
<Where>
<Eq>
<FieldRef Name='ContentType' />
<Value Type='Text'>Folder Content Type</Value>
</Eq>
</Where>"
$queryModified = New-Object Microsoft.SharePoint.SPQuery
$queryModified.Query = "@
<Where>
<Eq>
<FieldRef Name='ContentType' />
<Value Type='Text'>Document Content Type</Value>
</Eq>
</Where>"
#Get List Items matching the query
$items = $list.GetItems($queryOriginal) //result
$items2 = $list.GetItems($queryModified) //zero result*****
$items3 = $list.GetItems() //zero result*****
Edit:
Tried using <Neq>
but to no avail as well.
You can check the PowerShell script below.
#Set config variables
$baseUrl="http://test.com/"
$listName ="FilePlan"
#Get Web and List Objects
$web = Get-SPWeb $baseUrl
$list = $web.Lists[$listName]
$items = $list.Items
$items.Count
And then you can check if the ContentType is right for this list. You can provide more information about the list(custom list or document library and all the content types for this list) for further research.