I have this line of code made with PnP.

(Get-PnPList | ? {$_.Title -like "Stand-By*"} | select Title).count

But I need it change too CSOM code. I don't know how to do that/

Gr. P

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") #| Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") #| Out-Null
Add-Type -Path "c:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.Online.SharePoint.Client.Tenant.dll"

$username = "login@domain.com"
$password = ConvertTo-SecureString "Password" -AsPlainText -Force

$siteUrl = [string]::Format("https://company.sharepoint.com/sites/zvi/")
$cc = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$cc.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)

$lists = $cc.Web.Lists
$i = 0
foreach($list in $lists)
    if($list.Title -like "Doc*")
Write-Host "Count of Standb lists:" $i    

Hope it helps!

  • I get an error. How can I search for all list begin with "Standby*) – Peter Kiers Feb 25 at 11:36
  • $countlist = $Context.Web.Lists.GetByTitle("Stand-By*") $Context.Load($countlist); $Context.ExecuteQuery(); $countlist.ItemCount – Peter Kiers Feb 25 at 11:37
  • edited sorry, badly read :) – Zdeněk Vinduška Feb 25 at 11:58
  • It gives me the row count of each list. But I need how many lists are there beginning with "Standb*" – Peter Kiers Feb 25 at 12:11
  • no its filtering by the name -like Standb*, so if you have 30lists/libraries and 5 of them are starting with Standb, you will got only 5 outputs – Zdeněk Vinduška Feb 25 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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