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?

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? Commented Mar 10 at 15:39
  • I'm copy and pasting the whole script into the terminal Commented Mar 10 at 15:46
  • Are you getting an exception? Commented Mar 10 at 16:29

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.