0

One of our monitoring tool is getting replaced by another tool.

So I need to generate a report all lists items/libraries and documents where the old tool name is referred and take action. I have to check this in both SharePoint Online and SharePoint 2013 on-prem farms.

Possible to get this report as excel in OOB or using PS script?

1

Do you wish to generate a report on search result of certain keyword (old tool name)?

If that is the scenario, here is a sample script for SharePoint on-premises:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Set Parameters
$SiteURL = "http://sp"
$CSVFile = "C:\Temp\SearchResults.csv"
$SearchQuery = "<old tool name>"
 
#Get the site collection
$Site = Get-SPSite $SiteURL
 
#Frame Query to search: Get all documents sorted by Last modified
$keywordQuery = New-Object Microsoft.Office.Server.Search.Query.KeywordQuery($Site)
$keywordQuery.QueryText = $SearchQuery
$keywordQuery.SortList.Add("LastModifiedTime","Asc")
 
#Execute Search
$SearchExecutor = New-Object Microsoft.Office.Server.Search.Query.SearchExecutor
$searchResults = $SearchExecutor.ExecuteQuery($keywordQuery)
 
#Get Search Results
$Table = $SearchResults.Table
$Table | select Title, Path, Author, LastModifiedTime
 
#Export Search results to Excel
$Table | Export-Csv $CSVFile -NoTypeInformation
 
Write-Host -f Green "Search Results Exported to CSV File!"

And for SharePoint Online:

#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"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Search.dll"
 
#Config Variables
$SiteURL = "https://crescenttech.sharepoint.com/"
$SearchQuery = "<old tool name>"
$CSVFile = "C:\Temp\SearchResults.csv"
 
Try {
    $Cred= Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials
     
    #Define Keyword
    $KeywordQuery = New-Object Microsoft.SharePoint.Client.Search.Query.KeywordQuery($Ctx)
    $KeywordQuery.QueryText = $SearchQuery
    $KeywordQuery.RowLimit  = 500
    $keywordQuery.SelectProperties.Add("CreatedBy")
    $keywordQuery.SelectProperties.Add("LastModifiedTime")
    $keywordQuery.SortList.Add("LastModifiedTime","Asc")
 
    #Execute Search       
    $SearchExecutor = New-Object Microsoft.SharePoint.Client.Search.Query.SearchExecutor($Ctx)
    $SearchResults = $SearchExecutor.ExecuteQuery($KeywordQuery)
    $Ctx.ExecuteQuery()
 
    Write-host "Search Results Found:"$SearchResults.Value[0].ResultRows.Count
 
    #Get Search Results
    If($SearchResults) {
        $Results = @()
        foreach($Result in $SearchResults.Value[0].ResultRows) {
            $Results += New-Object PSObject -Property @{
                'Document Name' =  $Result["Title"]
                'URL' = $Result["Path"]
                'Created By' = $Result["CreatedBy"] 
                'Last Modified' = $Result["LastModifiedTime"]              
            }
        }
        $Results
        
        #Export search results to CSV
        $Results | Export-Csv $CSVFile -NoTypeInformation
        Write-Host -f Green "Search Results Exported to CSV File!"
    }
}
Catch {
    write-host -f Red "Error Getting Search Results!" $_.Exception.Message
}

Note: If you don’t specify site URL in the search query, it will generate a report at web application/tenant scope.

References:

PowerShell to Search SharePoint and Export Results to CSV using Keyword Query.

SharePoint Online: Find All Documents using Keyword Query PowerShell.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.