Forum Discussion
Upload of Network Share to Sharepoint Document Library
Dear All,
we would like to upload a network share to Sharepoint Online keeping the same folder hiercachy and also an important metadata like:
Created
Created By
Modified
Modified By
Owner
Security
Is it possible to achieve this using powershell scripts or maybe Microsoft has a tool which is intended to upload a network share to Sharepoint?
5 Replies
- Anonymousi would seiously recommend a tool like ShareGate,Bititan avepoint etc.
- Dean_GrossSilver Contributor
I'm not aware of a tool from MS to do this.
There are many 3rd party tools, from vendors like Metalogix, ShareGate and Others
the tricky part is the Security because your on-premises accounts must be mapped to their cloud equivalents.
I have found that many of my clients wanted to do this, but after demonstrating the benefits of multiple document libraries with metadata and views, they changed their mind. A direct file share copy typically prevents the users from realizing many of the benefits of SharePoint.
- SanthoshB1Bronze Contributor
This script will give you the highlevel attributes such as Created time and Modified time. Please modify the script with the required attributes.
You need to create a csv file with columns Sitename (Site url) and UserFolder (Parent folder path).
Downlaod the file 'uploadfiles.psm1' from the attachment and place it in a folder. Replace the Import-Module path with the path in which the psm1 file was placed and run the script.
FYI: This script can also be used to copy files to multiple sites by mapping the site urls in the csv.
#$cred= Get-Credential $csv = Import-Csv 'C:\csv\users3.csv' $User = "Admin@tenantname.com" $Password = "password" #Add references to SharePoint client assemblies and authenticate to Office 365 site – required for CSOM Add-Type -Path ([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client").location) Add-Type -Path ([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.runtime").location) Import-Module C:\uploadfiles.psm1 Foreach($Channel in $csv) { $SiteURL = $Channel.Sitename $Folder = $Channel.UserFolder $rootfolder=$folder.Replace("\","\\") $libraryName = "Documents" #Bind to site collection $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$(convertto-securestring $Password -asplaintext -force)) $ctx.Credentials = $Creds $Web = $ctx.Web $ctx.Load($Web) $ctx.ExecuteQuery() #Retrieve list $ParentFolder = $ctx.Web.Lists.GetByTitle($libraryName).RootFolder $ctx.Load($ParentFolder) $ctx.ExecuteQuery() Function UploadFiles($web,$path,$docLibrary) { $files = Get-ChildItem $path foreach ($file in $files) { if($file.GetType().Name -eq "DirectoryInfo") { $foldername=$file $parent=$file.Parent.FullName $parent1=$parent+"\" If($parent1 -eq $Folder) { $folder = $ParentFolder.Folders.Add($foldername) $ParentFolder.Context.Load($folder) $ParentFolder.Context.ExecuteQuery() $CreationTime= $foldername.CreationTime $LastAccessTime=$foldername.LastWriteTime $item1 = $folder.ListItemAllFields $item1["Modified"] =$LastAccessTime $item1["Created"] =$CreationTime $item1.Update() $ctx.ExecuteQuery() $CreationTime=$null $LastAccessTime=$null } Else { $Urlpath1= ($parent -split "$rootfolder" )[1] $foldernames1=$Urlpath1 if($foldernames1 -like "*\*") { $foldername1=$foldernames1.Replace("\","/") } Else { $foldername1=$foldernames1 } $ServerRelativeUrlOfRootFolder = $ParentFolder.ServerRelativeUrl $uploadFolderUrl= $ServerRelativeUrlOfRootFolder+"/"+$foldername1 $targetFolder = $ctx.Web.GetFolderByServerRelativeUrl($uploadFolderUrl) $Upload = $targetFolder.Folders.Add($foldername); $targetFolder.Context.Load($Upload) $targetFolder.Context.ExecuteQuery() $CreationTime= $foldername.CreationTime $LastAccessTime=$foldername.LastWriteTime $item = $Upload.ListItemAllFields $item["Modified"] =$LastAccessTime $item["Created"] =$CreationTime $item.Update() $ctx.ExecuteQuery() $CreationTime=$null $LastAccessTime=$null } $Folderpath1=$file.FullName UploadFiles $web $Folderpath1 $docLibrary } Else { $filepath= [System.IO.Path]::GetDirectoryName($file.FullName) $Urlpath= ($filepath -split "$rootfolder" )[1] $foldernames=$Urlpath if($foldernames -like "*\*") { $foldername=$foldernames.Replace("\","/") } Else { $foldername=$foldernames } $CreationTime= $file.CreationTime $LastAccessTime=$file.LastWriteTime $test=UploadFileInSlice -ctx $web -libraryName $docLibrary -foldername $foldername -fileName $File.FullName -CreationTime $CreationTime -LastAccessTime $LastAccessTime $foldername=$null $CreationTime=$null $LastAccessTime=$null } } } UploadFiles -web $ctx -path $Folder -docLibrary $libraryName }Does anyone have a PowerShell script that just inventories the fileshare? Captures filenames and paths and file sizes and identifies ones that that might cause issues with migration to SharePoint or OneDrive?
I agree with the other comment elsewhere in this thread, that a pure lift & shift misses many of the adavanages of OneDrive and SharePoint. However, having a way to quantify the volume of content to be considerd for migration and being able to see a list of all the files in a spreadsheet seems like it would be very helpful.
- JayCatsBrass ContributorShareGate can help. I don't know about powershell.