如何开始呢?

How to get started on this?

如果我提供站点名称和列表名称,脚本应该先删除列表中的项目,然后再删除列表?这在 powershell 或 javascript 中可能吗?谁能帮我? 这是针对 SharePoint online 那么如何使以下代码适用于 SharePoint online?

##  SP URL
Write-Host "Provide SharePoint URL:" -ForegroundColor Yellow
$webURL = Read-Host
$web = Get-SPweb $webURL
 
## LIST NAME
Write-Host "Enter name of the list:" -ForegroundColor Yellow
$listName = Read-Host
$list = $web.lists[$listName]
 
## SET QUERY
$query = New-Object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = "Scope='Recursive'"
$query.RowLimit = 1000
$query.ViewFields = "<FieldRef Name='ID'/>"
$query.ViewFieldsOnly = $true
 
 
## EXECUTE
do
{
    $listItems = $list.GetItems($query)
    $query.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
 
    foreach ($item in $listItems)
    {
        Write-Host "Deleting Item - $($item.Id)" -ForegroundColor Yellow
        $list.GetItemById($item.Id).delete()
    }

   
 
#Reset the "Allow Deletion" Flag
$list.AllowDeletion = $true
$list.Update()
 
$list.Delete()



}
while ($null -eq $query.ListItemCollectionPosition)
 
Write-Host "Script finished." -ForegroundColor Green ``````````````

从指定列表中删除项目 or/and 列表本身可以使用 PowerShell 和 javascript。

您可以尝试使用 pnp powershell:

删除项目:

Get-PnPList -Identity Lists/MyList | Get-PnPListItem -PageSize 100 -ScriptBlock { Param($items) 
$items.Context.ExecuteQuery() } | % {$_.DeleteObject()}

删除列表:

Remove-PnPList -Identity "test5" -Force

直接删除整个列表,该项也会被删除

下载 pnp powershell here