Copy Files with metadata to SharePoint Online with PowerShell

I finally created something I felt worthy of blogging. 🙂

From talking to customers I know that a current challenge is migrating Files and File Shares to SharePoint Online. Sure uploading a bunch of content from the browser is doable but what if you want to keep the Created By, Created Date, and Modified Date as you upload that content? Well, thanks to the PNP PowerShell and a little elbow grease I have solved the puzzle. The long story short here is the PowerShell:

Get-ChildItem '\\DESKTOP-3Q38SP3\demo' |  Where-object {$_.PSIsContainer -ne $True}  | ForEach-Object {
	$own = $_.GetAccessControl().owner;
	$who = get-pnpuser | Where-Object{$_.LoginName -match "$own"} | select id;
	Add-PnPFile -Path $_.FullName -folder FileShare -Values @{Author=$;Editor=$;Created=$_.CreationTimeUtc; Modified=$_.LastWriteTimeUtc;}

For most people, just the code isn’t enough context which is fair. But instead of typing a 2000 word essay I made a video that breaks that down into baby steps and shows you how to use and things to look out for. You can watch the video Upload files to SharePoint Online with Metadata to get all of the details. I have found videos to be the most effective way to teach this crazy stuff.

Also, if you just need to solve the problem and you are looking for awesomeness then check out this function I wrote to do it all for you in one fell swoop.

To see it in action check out Copy File Share to SharePoint Online

I hope this all helps you out.

Shane @shanescows


Leave a Reply