In this SharePoint list there is a column named College. How do I retrieve the count of items who have been to that particular college using PowerShell script from that list

  • 1
    A simple google search provided me below link. gallery.technet.microsoft.com/office/…
    – P S
    Commented Dec 3, 2018 at 7:14
  • 6
    Please do your own research before posting question
    – P S
    Commented Dec 3, 2018 at 7:15
  • I applied the same thing in my code. I wanted to know if there is any keyword to get the output. Commented Dec 3, 2018 at 7:17

3 Answers 3


The following PowerShell script for your reference.


$web = get-spweb $siteUrl
$list = $web.lists[$listName]
$spQuery = New-Object Microsoft.SharePoint.SPQuery 
$spQuery.Query="<Where><Eq><FieldRef Name='College'/><Value Type='Text'>"+$college+"</Value></Eq></Where>" 
$items = $list.GetItems($spQuery)
write-host $items.Count

enter image description here


You can also try using PnP PowerShell. It has the lot of extension powershell commands targeting SharePoint object. Below is the sample PnP Powershell commands returns you the count of list items from list based on the condition.

PS C:\ktskumar> $cred = Get-Credential
PS C:\ktskumar> Connect-PnPOnline -Url https://tenant.sharepoint.com -Credential $cred
PS C:\ktskumar> $itemsCount = Get-PnPListItem -List "Sample List" -Query "<View><Query><Where><Eq><FieldRef Name='Category'/><Value Type='Text'>SampleCategory</Value></Eq></Where></Query></View>"
PS C:\ktskumar> $itemsCount.Count

WebURL: https://tenant.sharepoint.com List: Sample List FieldName: Category FieldValue: SampleCategory

I hope this helps you to get the ListItems count.


Here is the bit tricky one:



Connect-PnPOnline -Url $siteUrl -Credential(Get-Credential) Get-PnPList | Where-Object {$_.Title -Contains $listName} | Select-Object Title, ItemCount

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.