0

I am trying to get the Url for a list item attachment. From what I have seen, you should be able to access it like this

$listitems = Get-pnplistitem -List MyList

foreach($listitem in $listitems)
{
    $attachmentPath = $listitem.attachmentfiles.serverrelativeurl
}

Please excuse any syntax mistakes and terrible practices, but I think you get the idea. I just want to get the attachment url https://Mydomain/sites/mysite/Lists/Clients/Attachments/11/Testlogo.png

I am hopeful that I can then use that url for the set-pnpunifiedgroup -grouplogopath $attachmentpath.

  • Hi didn't get question, by above snippe you will only have one url after you successfully iterate all collection bcoz the variable is inside loop – Sunil Sahu Jun 11 at 11:28
0

You just need to again iterate the item attachment and bind were you require

$listitems = Get-pnplistitem -List MyList

foreach($listitem in $listitems)
{
  $AttachmentsColl = $listitem.AttachmentFiles
  ForEach($Attachment in $AttachmentsColl)
   {
    //get the file url here
    write-host  -f Green "Attachments Url! " + $Attachment.ServerRelativeUrl 
   }
}
  • That did it, didn't know I needed to iterate through the AttachmentFiles. Thanks for the help – shawncho Jun 11 at 16:16
0

You can put code in your for each item loop, this will get all attachments and Set grouplogopath. Though this takes of all attachments, ideally you should have only one attachment.

$attachments = ForEach-Object{
       Get-PnPProperty -ClientObject $listitem -Property "AttachmentFiles"
} 

$attachments | ForEach-Object { 
Set-PnPUnifiedGroup -Identity $group -GroupLogoPath $_.ServerRelativeUrl
}
  • Thanks for the help, I am actually using the attachment when I create the group in another function that I call later in the script. This helps though for when I get to that part. Thanks – shawncho Jun 11 at 16:19
  • above code was doing same...iterating though attachments and $_.ServerRelativeUrl to retrieve url of attachment... – Siddharth Vaghasia Jun 11 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.