• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2750
  • Last Modified:

Powershell - Copy file from network drive to Sharepoint library - Keep modified date


Is it possible to copy a PDF-file from a Network share into a SharePoint library and keeping the modified date, with powershell? So Sharepoint shows the lastwritetime as the modified date?
Sum Wum
Sum Wum
  • 2
1 Solution
Jayaraja JayaramanSharepoint Architect ConsultantCommented:
if its just one file then easy way would be , just upload the doc manually and update the modifed date using
$file.Item["Modified"] = datetime
Sum WumAuthor Commented:
It's about 700 files, so that's a no go :)
Jayaraja JayaramanSharepoint Architect ConsultantCommented:
still a ps would do to upload a file from network/file share to a sharepoint doc lib with additional parameters.

if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
     Add-PSSnapin Microsoft.SharePoint.PowerShell;

#Site Collection where you want to upload files
$siteCollUrl = "http://webapplication/sites/Upload"
#Document Library where you want to upload files
$libraryName = "Shared Documents"
#Physical/Network location of files
$reportFilesLocation  = "C:\Users\manas\Desktop\Files"

$spSourceWeb = Get-SPWeb $siteCollUrl;
$spSourceList = $spSourceWeb.Lists[$libraryName];

if($spSourceList -eq $null)
    Write-Host "The Library $libraryName could not be found."

$files = ([System.IO.DirectoryInfo] (Get-Item $reportFilesLocation)).GetFiles()
foreach($file in $files)
    #Open file
    $fileStream = ([System.IO.FileInfo] (Get-Item $file.FullName)).OpenRead()

    #Add file
    $folder =  $spSourceWeb.getfolder($libraryName)

    Write-Host "Copying file $file to $libraryName..."
    $spFile = $folder.Files.Add($folder.Url + "/" + $file.Name, [System.IO.Stream]$fileStream, $true)

    #Close file stream
Write-Host "Files have been uploaded to $libraryName.

or you could use this : https://spbulkdocumentimport.codeplex.com/ 

Run it anywhere. Every action is done using the Client Object Model, there is no need to install it on the server.
Support for Mixed authentication, both Windows and Forms
Import folders and files with all subfolders
Retain creation and modified date fields after moving to SharePoint
Retain author/editor fields from office documents after moving to SharePoint
Incompatible file names are renamed (filename too long, illegal characters)
Unsupported files (large filesize, blocked file extension, …) are skipped
Files already existing on SharePoint are skipped (no overwrite)
Successfully migrated files and folders can be moved to an “archive” folder
Detailed log (Log4Net) with info on migration issues
Option to skip creation of empty folders in SharePoint
Option to merge subfolders to a flat list in SharePoint.
Easy to run in batch when migrating several locations
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now