Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2015-01-07
3
Medium Priority
?
2,536 Views
Last Modified: 2015-01-13
Hi,

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?
0
Comment
Question by:Sum Wum
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Expert Comment

by:Jayaraja Jayaraman
ID: 40540789
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
item.Update();
0
 
LVL 1

Author Comment

by:Sum Wum
ID: 40543741
It's about 700 files, so that's a no go :)
0
 
LVL 8

Accepted Solution

by:
Jayaraja Jayaraman earned 2000 total points
ID: 40544761
still a ps would do to upload a file from network/file share to a sharepoint doc lib with additional parameters.

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
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."
    return;
}

$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
    $fileStream.Close();
}
$spSourceWeb.dispose();
Write-Host "Files have been uploaded to $libraryName.

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

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
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question