1

I'm using PnP Powershell for SP 2013. I'm trying to retrieve lists that support a particular custom Content Type ("Knowledge Document"). I'm having difficulty even getting the List Content Type to print. Ultimately I wanted to use Get-PnPList | ContentType = "My Custom Content Type"

function PopulateData($web, $incldeFileSize) {
        Write-Host "Current Site " $web.url -ForegroundColor Cyan 
                  $libs = Get-PnPList -Web $web | Where{($_.BaseType -eq "DocumentLibrary”) }

                  foreach($lib in $libs){
                    $ContentType = Get-PnPContentType -List $lib
                     write-host $ContentType
                     $libitems = (Get-PnPListItem -Web $web -List $lib -Fields "FileLeafRef","Name","Title","Author","Modified","Created","KBAbstract","KBContentAuthor","KBCategory","Publish","KBPublishDate").FieldValues

                       foreach($libitem in $libitems)
                         {

...
3
  • Does the solution you're looking for have to use the PnP Powershell commands? I know a great way to do this, but it uses the regular SharePoint 2013 Management Shell / Microsoft.SharePoint.PowerShell snap-in. I'm not familiar with the PnP stuff, so I don't know if there is an equivalent. Jul 12 '19 at 17:59
  • I'm afraid I've been instructed to use PnP. Thank you though! Jul 12 '19 at 18:13
  • Well, if there's any possibility of you pushing back on that and being able to use the regular SP 2013 Management Shell, you would be able to take advantage of SPContentTypeUsage.GetUsages(contentType), which returns a collection of SPContentTypeUsage objects, which have properties like Url and IsUrlToList, which would be quite helpful for what you are trying to do. Jul 12 '19 at 19:21
0

Please follow below steps which might be helpful:

  1. First fetch the lists on which content types are enabled:

    Get-PnPList | Select-Object Title, AllowContentTypes | Where-Object { $_.AllowContentTypes -Eq $true }
    
  2. Iterate through each list and fetch their associated content types:

    Get-PnPContentType -List *ListName* -Identity *ContentTypeTitle*
    
  3. If a list contains your content type then collect those list names.

0

You can actually do this with the following one-liner!

Get-PnPList -Includes ContentTypes | Where-Object {$_.ContentTypes | Where-Object Name -eq "Knowledge Document"}

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.