SharePoint Server 2016 migrate local network file share

PSmith 20 Reputation points

Hi team,

I'm planning to migrate local network file shares to my SharePoint 2016 farm. Please help.

A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,240 questions
0 comments No comments
{count} votes

Accepted answer
  1. AllenXu-MSFT 18,051 Reputation points Microsoft Vendor

    Hi @PSmith,

    It's recommended to migrate local network file shares to SharePoint using PowerShell. By using PowerShell, you can automate migrating the data, including files and folders, from the network file share to SharePoint. This can save time and resources while ensuring that the data is properly transferred and organized in SharePoint.

    Use this PowerShell script to import all files and folders from a network path to a SharePoint document library:

    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
    #Function to migrate all Files and Folders from FileShare to SharePoint
    Function Migrate-FileShareToSharePoint()
            [Parameter(Mandatory=$true)] [string] $SiteURL,
            [Parameter(Mandatory=$true)] [string] $TargetLibraryName,
            [Parameter(Mandatory=$true)] [string] $SourceFolderPath,
            [Parameter(Mandatory=$false)] [bool] $Overwrite = $False
        #Get the Target Folder to Upload
        $Web = Get-SPWeb $SiteURL
        $TargetLibrary = $Web.Lists[$TargetLibraryName]
        $TargetFolder= $TargetLibrary.RootFolder
        #Get All Files and Folders from the Source
        Get-ChildItem $SourceFolderPath -Recurse | ForEach-Object {
            #Get Source Item's metadata
            $CreatedDate= [DateTime]$_.CreationTime
            $ModifiedDate =  [DateTime]$_.LastWriteTime
            If ($_.PSIsContainer -eq $True) #If its a Folder!
                #Frame Target Folder URL
                $TargetFolderRelativeURL = $TargetFolder.ServerRelativeURL+$_.FullName.Replace($SourceFolderPath,[string]::Empty).Replace("\","/")           
                #$Subfolder = $Web.GetFolder($TargetFolder.URL + "/" + $_.Name)
                $FolderToCreate = $Web.GetFolder($TargetFolderRelativeURL)
                Write-host -f Yellow "Ensuring Folder '$TargetFolderRelativeURL'" -NoNewline
                #Ensure Target Folder Exists
                If ($FolderToCreate.Exists -eq $false)
                    #Create New Sub-Folder
                    $FolderToCreate.Item["Created"] = $CreatedDate
                    $FolderToCreate.Item["Modified"] = $ModifiedDate
                    Write-host -f Green "`tCreated Folder!"
                   Write-host -f Green "`tFolder Already Exists!"
            Else #If its a File
                $FolderToUpload = $TargetFolder.ServerRelativeURL + $_.DirectoryName.Replace($SourceFolderPath,[string]::Empty).Replace("\","/")
                $TargetFileURL = $FolderToUpload+"/"+$_.Name
                $SourceFilePath = $_.FullName
                Write-host -f Yellow "Ensuring File '$TargetFileURL'" -NoNewline
                #Check if file exists
                $FileToUpload = $Web.GetFile($TargetFileURL)
                If($FileToUpload.Exists -and $Overwrite -eq $False)
                    Write-host -f Green "`tFile Already Exists!"
                    #Get the file from disk
                    $FileStream = ([System.IO.FileInfo] (Get-Item $SourceFilePath)).OpenRead()
                    #Upload the File to SharePoint Library's Folder
                    $ParentFolder = $Web.GetFolder($FolderToUpload)
                    $FileToUpload = $ParentFolder.Files.Add($_.Name, $FileStream, $TRUE)
                    #Set Metadata
                    #Close file stream
                    Write-host "`tFile Uploaded Successfully!" -ForegroundColor Green
    #Set parameter values
    $SourceFolderPath= "\\Cre-LT575\Salaudeen\Project Documents" #Or any local path: "C:\Temp\Docs"
    #Call the function to Upload All files & folders from network Fileshare to SharePoint library
    Migrate-FileShareToSharePoint -SiteURL $SiteURL -SourceFolderPath $SourceFolderPath -TargetLibraryName $TargetLibraryName

    If the answer is helpful, please click "Accept as Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful