I try to realize a multiple directory upload to sharepoint Online with powershell. Sadly, I managed to pull an upload script off, that does it's thing, but I only want to alter the files on the server, that are older than the uploading ones.

In order to do so, I need to compare the LastModified or the LastWrite -Time? Is there a difference? tried both and nothing worked.

maybe I have to alter my script in a way to make it work like this. Can you tell my how?

OH AND: big problem seems to be, that i have sharepoint admin-rights, but I don't have access to the PSSnapins, because I am not ON the server, I have to write the script on Client-Side. I think this is the real problem. Maybe I should build a VM for Prototyping? Big thx!

Here is what I got right now:

$file = Get-ChildItem -Path $path -Recurse

    (dir $path -Recurse) | %{

    if($_.GetType().Name -eq "FileInfo"){

        $SPFoldername = $docLibraryName + $_.DirectoryName.Substring($path.Length)

There is where the trouble begins:

        $dateA= $file.lastWriteTime
        $dateB = Get-PnPFolderItem -FolderSiteRelativeURL "Sites/xxx/Documents"

        if ($dateA -ge $dateB) {
            Write-Host "No Upload. "$dateA" / "$dateB
            } else {
            Write-Host "Upload. "$dateA" / "$dateB
            new = 1

        if ($new) {

           $addfile = Add-PnPFile -Path $_.FullName -Folder $SPFolderName
           } else {
           Write-Host "Upload-Data is older than Server-Data."

$dateB gets no DATA whatsoever and dateA gives ~20 dates. -.- What should I do? please help :O

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.