【发布时间】:2021-01-21 07:48:53
【问题描述】:
我希望使用 Add-PnPFile 将文件上传到 SharePoint,但它每次都会覆盖文件。 我想检查文件是否存在?如果是,那么是否在最后一天进行了修改? 如果是,那么我将上传文件(使用 add-pnpfile 覆盖现有文件)否则我跳过文件并检查下一个文件?
还有吗?
#install and import module
Import-Module SharePointPnPPowerShellOnline
#Get Connection to the url
Connect-PnPOnline "Some SharePoint Url" -UseWebLogin
#get the files from a local folder
$Files = Get-ChildItem "C:\Some Local FolderPath" -Recurse
#Now check wether the file is being modified or not ?
foreach($File in $Files){
#Logic to check if the file exists in the sharepoint folder or not ? If it exist then i want to check wether it is being modified or not ? if yes then i will add the file
#if not then i will skip that file and check for other files.
#Calculating LastWritetime for the file.
$LastWriteTimeForThisFile = $File.LastWriteTime.Day
$difference = (Get-Date).Day - $LastWriteTimeForThisFile
if(file exists ? then check the difference in Lastmodified dates)
if ( $difference -lt 1)
{
$upload = Add-PnPFile -Path $File.FullName -Folder $SharePointFolderPath
$message = "Successfully Uploaded" #this i will be having an entry in log file.
}
else{
$message = Not Modified so not uploading again #this i will be having an entry in log file.
}
}
【问题讨论】:
标签: powershell sharepoint file-upload sharepoint-online last-modified