Wednesday, November 18, 2015

Copy a file from SharePoint without Microsoft.SharePoint.Powershell Snap-in

My requirement is to find the most up-to-date file in a SharePoint document library.  The caveat is that I cannot run PowerShell on the SharePoint server.  So how do we do this?

First, determine the File Explorer address of your document library.
  • Check to see if the 'webclient' service is running:
  • Copy the SharePoint document library URL and paste it to your local text editor.
    • SharePoint URL example: http://sharepoint.url.com/site/Your_Site_Name/Sub_Site/SharedDocuments/
  • Drop the "http:" from the URL
  • Switch all of the "/" to "\", so your folder location looks like this:
    •  \\sharepoint.url.com\site\Your_Site_Name\Sub_Site\SharedDocuments\
  • Copy this new address, click on 'Start', then 'Run', paste the new location text, then click 'OK'.
  • You may have to play around with the location name, but once you get it, Explorer will open up and you will see the folders and/or the documents in that Share Documents directory. 

Second, using PowerShell, determine the most-up-to-date file and copy it.


$dir = "\\sharepoint.url.com\WWWRoot\site\Site_Name\Sub_Site\SharedDocuments\Folder_1\Sub_Folder_1\File_Name*"
$latest = Get-ChildItem -Path $dir | Sort-Object LastAccessTime -Descending | Select-Object -First 1
$latest.name

$fromfile = "\\sharepoint.url.com\WWWRoot\site\Site_Name\Sub_Site\SharedDocuments\Folder_1\Sub_Folder_1\"+$latest.name
$tofile   = "c:\temp\YOURE_FILE.xlsx"

Copy-Item $fromfile $tofile

  • If you know part of the file name, your can put that at the end of the directory ($dir) location and add a "*" for a wildcard search.



No comments:

Post a Comment