find email id located anywhere under a site collection

Chirag Shukla 41 Reputation points
2023-09-27T19:45:10.7566667+00:00

Hello Friends,

Is there any PowerShell script which can find a specific email ID located anywhere under a site collection? eg: it may be there under group, column name, comments column, etc. Let me know please.

Thanks,

CS

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,695 questions
SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,941 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,517 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 44,331 Reputation points
    2023-09-28T11:24:07.98+00:00
    Hello ,
    
    Yes, this is possible, but through scripting. Here's a PowerShell script example that can help you search for a specific email address within a SharePoint site collection:
    
    # SharePoint Online Module (for SharePoint Online)
    # Install-Module -Name SharePointPnPPowerShellOnline
    
    # SharePoint On-Premises Module (for SharePoint On-Premises)
    # Install-Module -Name SharePointPnPPowerShell2019
    
    # Connect to SharePoint
    Connect-PnPOnline -Url <insertyourSharepointURLhere> -UseWebLogin
    
    # Specify the email address you want to search for
    $emailToSearch = "<insertheretheemailtocheckfor>"
    
    # Search for the email address within lists and libraries
    $lists = Get-PnPTenantSite | Get-PnPTenantSiteList
    foreach ($list in $lists) {
        $items = Get-PnPTenantSiteListItem -List $list.Title
        foreach ($item in $items) {
            $fields = Get-PnPTenantSiteListItemFieldValues -List $list.Title -Identity $item.Id
            foreach ($field in $fields.Keys) {
                $fieldValue = $fields[$field]
                if ($fieldValue -match $emailToSearch) {
                    Write-Host "Found in list $($list.Title), item $($item.Id), field $field"
                }
            }
        }
    }
    
    # Search for the email address in site columns and content types
    $contentTypes = Get-PnPTenantSiteContentType
    foreach ($contentType in $contentTypes) {
        $fields = Get-PnPTenantSiteContentTypeField -Identity $contentType.Name
        foreach ($field in $fields) {
            $fieldXml = $field.SchemaXml
            if ($fieldXml -match $emailToSearch) {
                Write-Host "Found in content type $($contentType.Name), field $($field.InternalName)"
            }
        }
    }
    
    # Disconnect from SharePoint
    Disconnect-PnPOnline
    
    This script uses the SharePoint PnP PowerShell module to connect to your SharePoint site collection. Before using this script, make sure to:
    
    1.Install the SharePoint PnP PowerShell module appropriate for your SharePoint environment (Online or On-Premises) as shown in the comments at the beginning of the script.
    2.Replace ""https:// your-sharepoint- site-url"" with the actual URL of your SharePoint site collection.
    3.Set $emailToSearch to the email address you want to search for.
    
    Reference: https://learn.microsoft.com/en-us/powershell/sharepoint/sharepoint-pnp/sharepoint-pnp-cmdlets
    
    --If the reply is helpful, please Upvote and Accept as answer--
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.