Hi,
I’m looking for a solution to upload all the pictures that I have in a specified directory and his subdirectories to sharepoint online.
I can list all the pictures in my directory and his subdirectories using :
Get-ChildItem -Recurse -Path "C:\Users\Administrateur\Desktop\tests_onedrive\travail" -Include *.jpg,*.bmp -ErrorAction silentlycontinue | ForEach {
Write-Progress -activity "Fichiers Multimédia" -Status $_.FullName
$extension = $_.name.split(".")[-1]
}
I can upload all the files in a specified directory to Sharepoint online using :
#Specify tenant admin and site URL
$User = "user@sic.nc"
$SiteURL = "https://society-my.sharepoint.com/personal/user_sic_nc";
$Folder = "C:\Users\Administrateur\Desktop\TEST\Photos"
$DocLibName = "Documents"
#Add references to SharePoint client assemblies and authenticate to Office 365 site – required for CSOM
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
$Password = ConvertTo-SecureString 'password' -AsPlainText -Force
#Bind to site collection
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
$Context.Credentials = $Creds
#Retrieve list
$List = $Context.Web.Lists.GetByTitle("$DocLibName")
$Context.Load($List)
$Context.ExecuteQuery()
#Upload file
Foreach ($File in (dir $Folder -File))
{
$FileStream = New-Object IO.FileStream($File.FullName,[System.IO.FileMode]::Open)
$FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
$FileCreationInfo.Overwrite = $true
$FileCreationInfo.ContentStream = $FileStream
$FileCreationInfo.URL = $File
$Upload = $List.RootFolder.Files.Add($FileCreationInfo)
$Context.Load($Upload)
$Context.ExecuteQuery()
}
But I don’t know how get something like this :
I have approximately 35 000 pictures in 1 800 subfolders and my users frequently add new pictures. That why I need a script to automate the export to Sharepoint online
On my local computer I have :
C:\Docs\image.jpg C:\Docs\text.doc C:\Docs\Subfolder1\something.txt C:\Docs\Subfolder1\photo.jpg C:\Docs\Subfolder1\subfolder2\my_text.doc C:\Docs\Subfolder1\subfolder2\one_picture.jpg C:\Docs\Subfolder3\meeting.txt C:\Docs\Subfolder3\image.jpg ...
I need a script that build something like this on my sharepoint online :
https://society-my.sharepoint.com/personal/user_society_nc/Documents/Docs/images.jpg https://society-my.sharepoint.com/personal/user_society_nc/Documents/Docs/Subfolder1/photo.jpg https://society-my.sharepoint.com/personal/user_society_nc/Documents/Docs/Subfolder1/subfolder2/one_picture.jpg https://society-my.sharepoint.com/personal/user_society_nc/Documents/Docs/Subfolder3/image.jpg ...
Thanks for your help,
Olivier