我正在尝试使用 powershell csom 从在线共享点中提取项目列表

I'm trying to pull a list of items from sharepoint online using powershell csom

我可以获得列表数据 - 但它是所有列表历史记录,而不仅仅是项目的最新版本。我没有看到用于过滤项目旧版本的版本 ID 字段。有没有办法用 csom 和 powershell 做到这一点?

这是我当前的代码 - 我只需要一种方法来过滤活动项目。

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
   
#Variables for Processing
$SiteUrl = "XYZ"
$ListName="ABC"

#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
#Set up the context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Context.Credentials = $credentials
   
#Get the List
$List = $Context.web.Lists.GetByTitle($ListName)
 
#sharepoint online get list items powershell
$ListItems = $List.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
$Context.Load($ListItems)
$Context.ExecuteQuery()      
 
write-host "Total Number of List Items found:"$ListItems.Count

#Loop through each item
$ListItems | ForEach-Object {
    If ($_["Status"]  = "Returned") {
        #Get the Title field value
        write-host $_.ID
        write-host $_["Title"]
    }
}

请运行以管理员身份使用以下 PowerShell CSOM 脚本:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
   
#Variables for Processing
$SiteUrl = "https://****.sharepoint.com/sites/sitename"
$ListName="ABC"

#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
#Set up the context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$Context.Credentials = $credentials
   
#Get the List
$List = $Context.web.Lists.GetByTitle($ListName)
 
#sharepoint online get list items powershell
$Query = New-Object Microsoft.SharePoint.Client.CamlQuery
$Query.ViewXml = "<View><ViewFields><FieldRef Name='ID'/><FieldRef Name='Title'/></ViewFields><Query><Where><Eq><FieldRef Name='Status'/><Value Type='Choice'>Returned</Value></Eq></Where></Query></View>"

$ListItems = $List.GetItems($Query)
$Context.Load($ListItems)
$Context.ExecuteQuery()
 
Write-host "Total Number of Items:"$ListItems.count
 
#Loop through each List Item
$ListItems | ForEach-Object {
     #Get the Title field value
     write-host $_.ID
     write-host $_["Title"]  
     Write-host " ************* "
}

========================== 更新答案 ======= ==================

$Query = New-Object Microsoft.SharePoint.Client.CamlQuery
$Query.ViewXml = "<View><ViewFields><FieldRef Name='ID'/><FieldRef Name='Title'/></ViewFields><Query><Where><Eq><FieldRef Name='Status'/><Value Type='Choice'>Returned</Value></Eq></Where></Query></View>"

查询当前列表中[Status]列值为“已退货”的商品