简体   繁体   中英

Powershell PnP Sharepoint

How to upload the files and update the metadata while uploading the file? I want to upload a file and (on SharePoint I have a column like deleteFromLocal flag = no, so when i upload the file it should be changed to yes once the file gets uploaded). Is there any way?

Code till now:

Import-Module SharePointPnPPowerShellOnline 

#Get Connection to the url , #Connect-PnPOnline $URL 

Connect-PnPOnline "Some SharePoint Url" -UseWebLogin

$Files = Get-ChildItem "Local Folder Path which contains the files"

foreach($File in $Files){
    
    $upload = Add-PnPFile -Folder "some folder inside Shared Documents in sharepoint" -Path $File.FullName
    if($upload.UniqueId){
        $successCounter += 1
        $message = "Successfully Uploaded" 
    } else {
        $failCount +=1
        $message = "ERROR - Unable to Upload"
    }
    }

Edit: Files are uploading successfully, but I want to modify the column/add a column if possible via this script itself, instead of adding manually(Column - Metadata like a flag which will tell me Yes/no - wether the file is successfully uploaded or not, so that in future when required i can get that flag and do what is necessary).

Suppose the Yes/No field is "deleteFromLocal", then append -value parameter to set this field like this:

$upload = Add-PnPFile -Folder "some folder inside Shared Documents in sharepoint" -Path $File.FullName  -Values @{deleteFromLocal=$true}

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM