Skip to main content

List Attachment Names From SharePoint Lists For A Site

Author: Veronique Lengelle

$siteUrl = "https://<TENANT-NAME>.sharepoint.com/sites/<YOUR-SITE>"
$allLists = m365 spo list list --webUrl $siteUrl --query "[?BaseTemplate == ``100``]" | ConvertFrom-Json
$results = @()

foreach($list in $allLists){
if ($list.Hidden -eq $false){
$allItems = m365 spo listitem list --listId $list.Id --webUrl $siteUrl | ConvertFrom-Json

foreach($item in $allItems){
$allAttachments = m365 spo listitem attachment list --webUrl $siteUrl --listTitle $list.Title --listItemId $item.Id | ConvertFrom-Json

foreach($attachment in $allAttachments){
$results += [pscustomobject][ordered]@{
itemID = $item.Id
itemTitle = $item.Title
fileName = $attachment.FileName
attachmentPath = $attachment.ServerRelativeUrl
}
}
}
}
}
$results
CTRL + M