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:

[sourcecode language=”powershell”]

#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
}
}

[/sourcecode]

 

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.

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

Be the first to comment

Leave a Reply

Your email address will not be published.


*