SharePoint Online: PowerShell kullanarak Yinelenen Liste Öğelerini Bulma ve Silme
Gereksinim: PowerShell'i kullanarak SharePoint Online listesindeki Yinelenen Öğeleri Bulma ve Silme.
PowerShell'i kullanarak SharePoint Çevrimiçi Listesindeki Yinelenen Satırları Bulma
Çok fazla veri içeren bir listeniz olduğunda kopyaların gizlice içeri girmesi kolaydır. Birisi aynı verileri iki kez girmiş olabilir veya bir içe aktarma işlemi kopyaları oluşturmuş olabilir. Durum ne olursa olsun, yinelenen öğeler SharePoint Online listelerinizde yanlış raporlamadan, sıralama ve filtrelemenin başarısız olmasına kadar her türlü soruna neden olabilir. Tüm yinelenen öğeleri tek tek bulup silmek can sıkıcı ve zaman alıcı olabilir. Neyse ki, SharePoint Online'da yinelenen liste öğelerini hızlı bir şekilde bulup silmek için PowerShell'e sahibiz.
SharePoint'teki "Projeler" listesindeki yinelenen öğeleri şu sütuna göre bulalım: ProjeAdı.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Parameters
$SiteURL = "https://Crescent.sharepoint.com"
$ListName = "Projects"
$UserName = "Salaudeen@CrescentTech.com"
$Password = "Password"
$SecurePassword= $Password | ConvertTo-SecureString -AsPlainText -Force
#Setup the Context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
#Get All List Items
$List = $Ctx.Web.Lists.GetByTitle($ListName)
$ListItems = $List.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
$Ctx.Load($ListItems)
$Ctx.ExecuteQuery()
#Array for Results Data
$DataCollection = @()
ForEach($Item in $ListItems)
{
#Collect data
$Data = New-Object PSObject -Property @{
ProjectID = $Item["ProjectID"]
ProjectName = $Item["ProjectName"]
CreatedDate = $Item["Created"]
ID = $Item.Id
}
$DataCollection += $Data
}
#Get Duplicate Rows based on Column: ProjectName
$DataCollection | Sort-Object -Property ProjectName | Group-Object -Property ProjectName | Where-Object {$_.Count -gt 1} | Select-Object -ExpandProperty Group
Bu, listede bulunan aynı "ProjeAdı" değerine sahip tüm liste öğelerini alır.
SharePoint Çevrimiçi Listesinden Yinelenen Öğeleri Silmek için PowerShell
Şimdi ikinci bölüme geçelim: SharePoint Çevrimiçi Listesinden yinelenen satırlar nasıl kaldırılır? İşte SharePoint Online listesinden kopyaları silmek için PowerShell. Ancak bu kez kopyaları eşleştirmek için tek sütun yerine iki sütun kullanalım: “ProjeAdı” ve “ProjeKimliği”.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Parameters
$SiteURL = "https://Crescent.sharepoint.com"
$ListName = "Projects"
$UserName = "Salaudeen@CrescentTech.com"
$Password = "Password"
$SecurePassword= $Password | ConvertTo-SecureString -AsPlainText -Force
#Setup the Context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
#Get All List Items
$List = $Ctx.Web.Lists.GetByTitle($ListName)
$ListItems = $List.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
$Ctx.Load($ListItems)
$Ctx.ExecuteQuery()
#Array for Results Data
$DataCollection = @()
ForEach($Item in $ListItems)
{
#Collect data
$Data = New-Object PSObject -Property @{
ProjectID = $Item["ProjectID"]
ProjectName = $Item["ProjectName"]
CreatedDate = $Item["Created"]
ID = $Item.Id
}
$DataCollection += $Data
}
#Get Duplicate Rows based on Two Columns: ProjectID and ProjectName
$Duplicates = $DataCollection | Sort-Object -Property CreatedDate | Group-Object -Property ProjectID,ProjectName | Where-Object {$_.Count -gt 1}
#Leave the 1st Item as Original and Select the Second Item in the Group as Duplicate
ForEach($Duplicate in $Duplicates)
{
#Delete the Duplicate Row
$Duplicate.Group | Select-Object -Skip 1 | ForEach-Object {
$List.GetItemById($_.ID).Recycle() | Out-Null; Write-host "Deleted List Item:"$_.ID
}
$Ctx.ExecuteQuery()
}
