SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,695 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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
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--