3

I'm using PnP Powershell (which I'm new to) and I wish to find the URL of a document in a document library. The following returns Microsoft.SharePoint.Client.ObjectPathIdentity rather than an actual value. Here's my code:

$url = "https://tenant.sharepoint.com/teams/test"
Connect-PnPOnline –Url $url –Credentials (Get-Credential $userCredential)
$web = Get-PnPWeb

$ctx = Get-PnPContext

$libs = Get-PnPList | Where{$_.BaseTemplate -eq 101} 

foreach($lib in $libs)

{

$libitems = Get-PnPListItem -List $lib -Fields "FileLeafRef"

foreach($libitem in $libitems)

{

    if({$_.Name -match ".doc*"}) 

    {

        write-host "lib path... "$libitem.Path

     }

 }

}

The output is:

lib path... Microsoft.SharePoint.Client.ObjectPathIdentity followed by the Id, Title and Unique Id of all library items in the library.

Any thoughts? I was expecting the Path of the list item to be returned.

1 Answer 1

4

You need to use $libitem["FileRef"].

So, modify your inner foreach loop as below:

foreach($libitem in $libitems)
{
    if({$_.Name -match ".doc*"}) 
    {
        write-host "lib path... " $libitem["FileRef"]
    }
}

It gives you the server-relative path of the file.

Also,if you just want the file name, use $libitem["FileLeafRef"]

Your Answer

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

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