SharePoint 2013: Get File Size of List Attachments

Sometimes you just want to know how big are your attachments within a SharePoint list? Here you get a simple PowerShell Script to get these information

$file.Length

Sample list called “MySampleList” and as you can see there are more than one attachments added to file “Mein File 1”

Use the following code:



#Version 1.0
< #
.DESCRIPTION
.NOTES
File Name : GetListAttachmentInformation.ps1
Author : Dennis de Vries (ddv@inconsult-online.de)
Copyright 2014 : INCONSULT Volker Schäfer / Dennis de Vries
.LINK
..::ILikeSharePoint::..
www.ilikesharepoint.de
#>
$web = Get-SPWeb -Identity http://isv82/sites/ddv/
$list = $web.Lists["MySampleList"]
foreach ($item in $list.Items)
{
$attachmentCollection = $item.Attachments
$folder = $web.GetFolder($attachmentCollection.UrlPrefix);
foreach ($file in $folder.Files)
{
Write-Host $item.Title
Write-Host $file.Name
Write-Host $file.Length
}
}


 

Within the output you will get the File Size:

..::ILikeSharePoint::..

The article or information provided here represents completely my own personal view & thought. It is recommended to test the content or scripts of the site in the lab, before making use in the production environment & use it completely at your own risk. The articles, scripts, suggestions or tricks published on the site are provided AS-IS with no warranties or guarantees and confers no rights.

Dennis de Vries About Dennis de Vries
Loving SharePoint, Social Media and like to work together with creative people all over the world.

Submit comment

Allowed HTML tags: <a href="http://google.com">google</a> <strong>bold</strong> <em>emphasized</em> <code>code</code> <blockquote>
quote
</blockquote>

Please fill in the captcha: * Time limit is exhausted. Please reload CAPTCHA.