ค้นหาเว็บไซต์

จะลบรายการ SharePoint โดยใช้ PowerShell ได้อย่างไร


ปัญหา: โซลูชันที่ผิดพลาดที่ติดตั้งในฟาร์ม SharePoint ได้สร้างรายการที่ซ้ำกันในไซต์ทั้งหมดในไซต์คอลเลกชันขนาดใหญ่ที่มีไซต์มากกว่า 100 แห่ง เราต้องกำจัดพวกมันทั้งหมด!

หากต้องการลบรายการออกจาก SharePoint จากเบราว์เซอร์เราสามารถไปที่: ดูเนื้อหาไซต์ทั้งหมด >> คลิกที่ลิงก์ "ลบ" จากเมนูบริบทของรายการ หรือคุณสามารถเข้าสู่การตั้งค่ารายการ >> คลิกที่ "ลบรายการนี้" เพื่อลบรายการใน SharePoint

อย่างไรก็ตาม มีไซต์มากกว่า 100 แห่งที่ต้องลบรายการใดรายการหนึ่ง

ลบรายการ SharePoint โดยใช้ PowerShell

คำสั่ง PowerShell เพื่อลบรายการใน SharePoint:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Site collection URL 
$SiteUrl="https://your-sharepoint-site" 
$ListName = "List-Name-To-Delete"

#Get Web and List objects
$web = Get-SPWeb $SiteURL
$list = $web.Lists[$ListName]

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

$list.Delete()

write-host "List has been deleted successfully!"

หนึ่งบรรทัดสำหรับลบรายการ SharePoint โดยใช้ PowerShell:


Get-SPWeb "https://Your-Site-URL" | Where-Object { $_.Lists.Delete([System.Guid]$_.Lists["Your-List-Name"].ID) }

SharePoint PowerShell เพื่อลบรายการโดย GUID


Get-SPWeb "https://your-SharePoint-Site-URL" | Where-Object { $_.Lists.Delete([System.Guid]"{43c30f3a-f39a-4410-976c-a87bebb36e42}") }

เพียงแทนที่ URL ของเว็บและ GUID ด้วยของคุณและเรียกใช้สคริปต์

ให้สร้างฟังก์ชันแบบกำหนดเองเพื่อลบรายการ SharePoint โดยใช้สคริปต์ PowerShell


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Custom function to delete SharePoint list or document library using powershell
Function Delete-SPList
{
    param
    (
        [string]$WebURL  = $(throw "Please Enter the Web URL!"),
        [string]$ListName = $(throw "Please Enter the List Name to Delete!")
    )
    
    #Get the Objects 
    $Web = Get-SPWeb $WebURL
    $List = $Web.lists[$ListName]
 
    if($List)
    {
        #Set Allow Delete Flag
        $list.AllowDeletion = $true
        $list.Update()

        #delete list from sharepoint using powershell - Send List to Recycle bin
        $list.Recycle()
        
        #TO permanently delete a list, Use: 
        #$List.Delete()

        Write-Host "List: $($ListName) deleted successfully from: $($WebURL)"
    }
    else
    {
        Write-Host "List: $($ListName) doesn't exist at $($WebURL)"
    }
    $web.Dispose() 
}

#Call the function to delete list
Delete-SPList "https://intranet.crescent.com" "ConfigListv1"

ดังนั้นให้เรียกใช้ฟังก์ชันโดยวนซ้ำผ่านไซต์ต่างๆ:


#Site URL variable
$SiteURL ="https://intranet.crescent.com" 

#get the site collection
$Site = Get-SPSite $SiteURL

#Loop through each site in the site collection
Foreach($web in $site.Allwebs)
{
    #Call the function to delete list
    Delete-SPList $web.URL "ConfigListv1"
}

บังคับลบรายการ SharePoint ที่เสียหายโดยใช้ PowerShell:
ในบางกรณี คุณต้องการความช่วยเหลือจาก PowerShell เมื่อคุณไม่สามารถลบรายการออกจาก SharePoint web UI ได้ เนื่องจากรายการเสียหายและ SharePoint จะไม่ยอมให้คุณ ลบออก ใช้สคริปต์นี้เพื่อลบรายการ SharePoint โดยใช้ PowerShell: บังคับให้ลบรายการที่เสียหายใน SharePoint โดยใช้ PowerShell

บทความที่เกี่ยวข้อง