最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

sharepoint - Powershell script using Add-PnPFile to add same file to 2 different libraries isn't working - Stack Overflo

programmeradmin3浏览0评论

I wrote a script to add files to a document library within SharePoint. Pretty straightforward, however I now want to add that same file to a different document library depending on if certain criteria is met. Something like:

if ($Value -eq "DocumentLibrary1") {
    Add-PnPFile -Path $Path -Folder "DocumentLibrary1" -Values $HashTable

    Write-Host "PAUSE-------POLICY-----------------------" - ForegroundColor red -BackgroundColor white

    Add-PnPFile -Path $Path -Folder "DocumentLibrary2" -Values $HashTable
}
else {
    Add-PnPFile -Path $Path -Folder "DocumentLibrary3" - Values $HashTable
}

However this does not work for some reason and only add to the one document library (Document LIbrary 1 in my example) and skips over the rest. It doesn't even do the "Write" command i have immediately after even though the document gets added. Why is that?

I wrote a script to add files to a document library within SharePoint. Pretty straightforward, however I now want to add that same file to a different document library depending on if certain criteria is met. Something like:

if ($Value -eq "DocumentLibrary1") {
    Add-PnPFile -Path $Path -Folder "DocumentLibrary1" -Values $HashTable

    Write-Host "PAUSE-------POLICY-----------------------" - ForegroundColor red -BackgroundColor white

    Add-PnPFile -Path $Path -Folder "DocumentLibrary2" -Values $HashTable
}
else {
    Add-PnPFile -Path $Path -Folder "DocumentLibrary3" - Values $HashTable
}

However this does not work for some reason and only add to the one document library (Document LIbrary 1 in my example) and skips over the rest. It doesn't even do the "Write" command i have immediately after even though the document gets added. Why is that?

Share Improve this question edited Mar 10 at 15:38 Mathias R. Jessen 176k13 gold badges172 silver badges230 bronze badges asked Mar 10 at 15:28 DanielJDanielJ 1091 gold badge4 silver badges14 bronze badges 3
  • The behavior you describe could indicate that you're not actually running the latest version of your script - how are you executing the code? – Mathias R. Jessen Commented Mar 10 at 15:39
  • I'm copy and pasting the whole script into the terminal – DanielJ Commented Mar 10 at 15:46
  • Are you getting an exception? – jdweng Commented Mar 10 at 16:29
Add a comment  | 

1 Answer 1

Reset to default 0

Apparantly i've been hitting the else this whole time and not the If. Should've added a write host to the Else. Thank you all for your help

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论