-
Notifications
You must be signed in to change notification settings - Fork 0
/
Find-SPOFilesWithExtension.ps1
39 lines (31 loc) · 1.38 KB
/
Find-SPOFilesWithExtension.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#App Registration Permissions
#SharePoint Sites.Read.All (Application Permission)
#Parameters
$SharePointOnlineAdminUrl = "https://<tenant>-admin.sharepoint.com"
$clientID = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
$certThumbprint = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
$tenant = "<tenant>.onmicrosoft.com"
$FileExtensionToSearch = "exe"
$CSVFile = "C:\Temp\SharePoint_Files_" + $FileExtensionToSearch + ".csv"
$SearchQuery = "Filetype:" + $FileExtensionToSearch
#Connect to PnP Online
Connect-PnPOnline -Url $SharePointOnlineAdminUrl -Tenant $tenant -ClientId $clientID -Thumbprint $certThumbprint
#Execute Search
$SearchResults = Submit-PnPSearchQuery -Query $SearchQuery -All -TrimDuplicates $False -SelectProperties Filename, Path, Author, Size, ListItemID, LastModifiedTime, ParentLink
#Collect Data from search results
$Results = @()
ForEach ($ResultRow in $SearchResults.ResultRows)
{
$Results += [pscustomobject] @{
Filename = $ResultRow["Filename"]
Author = $ResultRow["Author"]
Size = $ResultRow["Size"]
LastModified = $ResultRow["LastModifiedTime"]
ListItemID = $ResultRow["ListItemID"]
ParentFolder = $ResultRow["ParentLink"]
URL = $ResultRow["Path"]
}
}
Write-Host "Total Results: $($Results.Count)"
#Export results to CSV
$Results | Export-Csv -Path $CSVFile -NoTypeInformation -Encoding UTF8