Jesper M. Christensen

SharePoint and Security

Check for duplicate items in Sharepoint lists with Powershell


Sometimes I need to check for duplicate E-mail addresses in my Sharepoint lists. In the beginning I looked for new items manually, but this will take….. a while now :o)

I came up with this script to report back if any address exists more than once:

 

##########################################################################
#
# Powershell script by Jesper M. Christensen
#
# Edited September 22. 2008
#
#
# Check for duplicate E-mail addresses
#
##########################################################################

$siteUrl = "http://intranet.domain.local"
$webName = "/"
$ContactslistName = "Contacts" 

#Set up connection
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$spSite = new-object Microsoft.SharePoint.SPSite($siteurl) 
$spWeb = $spSite.OpenWeb($webName)  

#Set up list connections
$spListContacts = $spWeb.Lists[$ContactslistName]
$spListContactsCol = $spListContacts.items

$DuplicateContacts=$spListContactsCol.GetDataTable() | Group-Object email | Where-Object {$_.count -gt 1} | Select-Object Name  

write-host "Duplicate Contacts found with E-mail address:"
$DuplicateContacts

 

Advertisements

4 responses to “Check for duplicate items in Sharepoint lists with Powershell

  1. Christian September 26, 2008 at 09:02

    Hi Jesper,
     
    thanks for your feedback.
    I see you felt in love with SharePoint and PowerShell too.
    Keep going!
     
    Bye, Christian
     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: