{"id":1088,"date":"2014-01-19T22:43:41","date_gmt":"2014-01-20T05:43:41","guid":{"rendered":"https:\/\/mmman.itgroove.net\/?p=1088"},"modified":"2023-02-24T21:48:35","modified_gmt":"2023-02-24T21:48:35","slug":"powershell-to-grab-a-collection-of-files-from-a-document-library","status":"publish","type":"post","link":"https:\/\/regroove.ca\/archive\/2014\/01\/19\/powershell-to-grab-a-collection-of-files-from-a-document-library\/","title":{"rendered":"PowerShell to Grab a Collection of Files from a Document Library"},"content":{"rendered":"<p>The following PowerShell can be used to take a subset of files from a document library in SharePoint and output them to the file system.\u00a0 Note, this will need to be executed on the SharePoint server.<br \/>\n[code language=&#8221;PowerShell&#8221;]<br \/>\n$spweb = get-spweb -identity &quot;http:\/\/yourdomain\/yourweb&quot;<\/p>\n<p># Use the &quot;pretty name&quot; of your library below<br \/>\n$list = $spweb.lists[&quot;Your Library&quot;]<\/p>\n<p># Below is an example of matching an attribute (Type) with a wildcard (*Queen*)<br \/>\n$listItemsLikeQueen = $list.Items | ?{$_[&quot;Type&quot;] -like &quot;*Queen*&quot;}<\/p>\n<p># Below is an example of matching based on a Content Type<br \/>\n$listItems = $listItemsLikeQueen | ?{$_.ContentType.Name -eq &quot;Monarchy&quot;}<br \/>\n$Destination = &quot;D:\\Out&quot;<\/p>\n<p># Use the name of your library as you named it at the time of creation below (we all remove spaces when we create libraries, right?)<br \/>\n$DocumentLibrary = &quot;YourLibraryWithoutSpaces&quot;<\/p>\n<p># For each item, output it to the destination path above<br \/>\nforeach ($listItem in $listItems)<br \/>\n{<br \/>\n    # Change the output path of the list item, and swap around the slashes<br \/>\n    $DestinationPath = $listItem.Url.replace(&quot;$DocumentLibrary&quot;,&quot;$Destination&quot;).Replace(&quot;\/&quot;,&quot;&quot;)<br \/>\n    write-host &quot;Downloading $($listItem.Name) -&gt; $DestinationPath&quot;<\/p>\n<p>    if (!(Test-Path -path $(Split-Path $DestinationPath -parent)))<br \/>\n    {<br \/>\n        write-host &quot;Creating $(Split-Path $DestinationPath -parent)&quot;<br \/>\n        $dest = New-Item $(Split-Path $DestinationPath -parent) -type directory<br \/>\n    }<br \/>\n    $binary = $spWeb.GetFile($listItem.Url).OpenBinary()<br \/>\n    $stream = New-Object System.IO.FileStream($DestinationPath), Create<br \/>\n    $writer = New-Object System.IO.BinaryWriter($stream)<br \/>\n    $writer.write($binary)<br \/>\n    $writer.Close()<br \/>\n}<\/p>\n<p>#Clean up<br \/>\n$spWeb.Dispose()<br \/>\n[\/code]<br \/>\nThe inspiration for this came from the following forum post<\/p>\n<p><a title=\"http:\/\/social.msdn.microsoft.com\/Forums\/sharepoint\/en-US\/75be246c-1ef4-4223-9531-ec87c1612e54\/copy-a-file-from-sharepoint-2010-to-file-share-with-powershell?forum=sharepointcustomization\" href=\"http:\/\/social.msdn.microsoft.com\/Forums\/sharepoint\/en-US\/75be246c-1ef4-4223-9531-ec87c1612e54\/copy-a-file-from-sharepoint-2010-to-file-share-with-powershell?forum=sharepointcustomization\">http:\/\/social.msdn.microsoft.com\/Forums\/sharepoint\/en-US\/75be246c-1ef4-4223-9531-ec87c1612e54\/copy-a-file-from-sharepoint-2010-to-file-share-with-powershell?forum=sharepointcustomization<\/a><\/p>\n<p>As well as this blog post (the blog post below shows you how to take ALL the files in a library and output them to a local path).<\/p>\n<p><a title=\"http:\/\/www.jbmurphy.com\/2012\/04\/25\/powershell-script-to-copy-a-sharepoint-document-library-to-a-local-path\/\" href=\"http:\/\/www.jbmurphy.com\/2012\/04\/25\/powershell-script-to-copy-a-sharepoint-document-library-to-a-local-path\/\">http:\/\/www.jbmurphy.com\/2012\/04\/25\/powershell-script-to-copy-a-sharepoint-document-library-to-a-local-path\/<\/a><\/p>\n<p>And some ideas of how to filter items in the list using PowerShell can be found below.<\/p>\n<p><a href=\"http:\/\/www.thorntontechnical.com\/tech\/sharepoint\/quick-tip-sharepoint-powershell-get-items-in-a-list-based-on-custom-columns-and-other-hints\">http:\/\/www.thorntontechnical.com\/tech\/sharepoint\/quick-tip-sharepoint-powershell-get-items-in-a-list-based-on-custom-columns-and-other-hints<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The following PowerShell can be used to take a subset of files from a document library in SharePoint and output them to the file system.\u00a0 Note, this will need to be executed on the SharePoint server. [code language=&#8221;PowerShell&#8221;] $spweb = get-spweb -identity &quot;http:\/\/yourdomain\/yourweb&quot; # Use the &quot;pretty name&quot; of your library below $list = $spweb.lists[&quot;Your &hellip; <a href=\"https:\/\/regroove.ca\/archive\/2014\/01\/19\/powershell-to-grab-a-collection-of-files-from-a-document-library\/\"><\/a><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[31,7],"tags":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PowerShell to Grab a Collection of Files from a Document Library - Archive<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/regroove.ca\/archive\/2014\/01\/19\/powershell-to-grab-a-collection-of-files-from-a-document-library\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PowerShell to Grab a Collection of Files from a Document Library - Archive\" \/>\n<meta property=\"og:description\" content=\"The following PowerShell can be used to take a subset of files from a document library in SharePoint and output them to the file system.\u00a0 Note, this will need to be executed on the SharePoint server. [code language=&#8221;PowerShell&#8221;] $spweb = get-spweb -identity &quot;http:\/\/yourdomain\/yourweb&quot; # Use the &quot;pretty name&quot; of your library below $list = $spweb.lists[&quot;Your &hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/regroove.ca\/archive\/2014\/01\/19\/powershell-to-grab-a-collection-of-files-from-a-document-library\/\" \/>\n<meta property=\"og:site_name\" content=\"Archive\" \/>\n<meta property=\"article:published_time\" content=\"2014-01-20T05:43:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-24T21:48:35+00:00\" \/>\n<meta name=\"author\" content=\"Colin Phillips (Alumni)\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Colin Phillips (Alumni)\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/regroove.ca\/archive\/2014\/01\/19\/powershell-to-grab-a-collection-of-files-from-a-document-library\/\",\"url\":\"https:\/\/regroove.ca\/archive\/2014\/01\/19\/powershell-to-grab-a-collection-of-files-from-a-document-library\/\",\"name\":\"PowerShell to Grab a Collection of Files from a Document Library - Archive\",\"isPartOf\":{\"@id\":\"https:\/\/regroove.ca\/archive\/#website\"},\"datePublished\":\"2014-01-20T05:43:41+00:00\",\"dateModified\":\"2023-02-24T21:48:35+00:00\",\"author\":{\"@id\":\"https:\/\/regroove.ca\/archive\/#\/schema\/person\/adeb0df1cc7a862160be620ca7eace1b\"},\"breadcrumb\":{\"@id\":\"https:\/\/regroove.ca\/archive\/2014\/01\/19\/powershell-to-grab-a-collection-of-files-from-a-document-library\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/regroove.ca\/archive\/2014\/01\/19\/powershell-to-grab-a-collection-of-files-from-a-document-library\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/regroove.ca\/archive\/2014\/01\/19\/powershell-to-grab-a-collection-of-files-from-a-document-library\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog Archive\",\"item\":\"https:\/\/regroove.ca\/archive\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PowerShell to Grab a Collection of Files from a Document Library\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/regroove.ca\/archive\/#website\",\"url\":\"https:\/\/regroove.ca\/archive\/\",\"name\":\"Archive\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/regroove.ca\/archive\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/regroove.ca\/archive\/#\/schema\/person\/adeb0df1cc7a862160be620ca7eace1b\",\"name\":\"Colin Phillips (Alumni)\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/regroove.ca\/archive\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/14eeab0d377e9630e0983d9c08911979?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/14eeab0d377e9630e0983d9c08911979?s=96&d=mm&r=g\",\"caption\":\"Colin Phillips (Alumni)\"},\"url\":\"https:\/\/regroove.ca\/archive\/author\/cphillips\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PowerShell to Grab a Collection of Files from a Document Library - Archive","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/regroove.ca\/archive\/2014\/01\/19\/powershell-to-grab-a-collection-of-files-from-a-document-library\/","og_locale":"en_US","og_type":"article","og_title":"PowerShell to Grab a Collection of Files from a Document Library - Archive","og_description":"The following PowerShell can be used to take a subset of files from a document library in SharePoint and output them to the file system.\u00a0 Note, this will need to be executed on the SharePoint server. [code language=&#8221;PowerShell&#8221;] $spweb = get-spweb -identity &quot;http:\/\/yourdomain\/yourweb&quot; # Use the &quot;pretty name&quot; of your library below $list = $spweb.lists[&quot;Your &hellip;","og_url":"https:\/\/regroove.ca\/archive\/2014\/01\/19\/powershell-to-grab-a-collection-of-files-from-a-document-library\/","og_site_name":"Archive","article_published_time":"2014-01-20T05:43:41+00:00","article_modified_time":"2023-02-24T21:48:35+00:00","author":"Colin Phillips (Alumni)","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Colin Phillips (Alumni)","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/regroove.ca\/archive\/2014\/01\/19\/powershell-to-grab-a-collection-of-files-from-a-document-library\/","url":"https:\/\/regroove.ca\/archive\/2014\/01\/19\/powershell-to-grab-a-collection-of-files-from-a-document-library\/","name":"PowerShell to Grab a Collection of Files from a Document Library - Archive","isPartOf":{"@id":"https:\/\/regroove.ca\/archive\/#website"},"datePublished":"2014-01-20T05:43:41+00:00","dateModified":"2023-02-24T21:48:35+00:00","author":{"@id":"https:\/\/regroove.ca\/archive\/#\/schema\/person\/adeb0df1cc7a862160be620ca7eace1b"},"breadcrumb":{"@id":"https:\/\/regroove.ca\/archive\/2014\/01\/19\/powershell-to-grab-a-collection-of-files-from-a-document-library\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/regroove.ca\/archive\/2014\/01\/19\/powershell-to-grab-a-collection-of-files-from-a-document-library\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/regroove.ca\/archive\/2014\/01\/19\/powershell-to-grab-a-collection-of-files-from-a-document-library\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Archive","item":"https:\/\/regroove.ca\/archive\/"},{"@type":"ListItem","position":2,"name":"PowerShell to Grab a Collection of Files from a Document Library"}]},{"@type":"WebSite","@id":"https:\/\/regroove.ca\/archive\/#website","url":"https:\/\/regroove.ca\/archive\/","name":"Archive","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/regroove.ca\/archive\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/regroove.ca\/archive\/#\/schema\/person\/adeb0df1cc7a862160be620ca7eace1b","name":"Colin Phillips (Alumni)","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/regroove.ca\/archive\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/14eeab0d377e9630e0983d9c08911979?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/14eeab0d377e9630e0983d9c08911979?s=96&d=mm&r=g","caption":"Colin Phillips (Alumni)"},"url":"https:\/\/regroove.ca\/archive\/author\/cphillips\/"}]}},"_links":{"self":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts\/1088"}],"collection":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/comments?post=1088"}],"version-history":[{"count":1,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts\/1088\/revisions"}],"predecessor-version":[{"id":1892,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/posts\/1088\/revisions\/1892"}],"wp:attachment":[{"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/media?parent=1088"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/categories?post=1088"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/regroove.ca\/archive\/wp-json\/wp\/v2\/tags?post=1088"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}