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
1 Answer
Reset to default 0Apparantly 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