0

I am trying to iterate through a collection of document libraries and run code on the ones that are of a particular Content-Type. The if statement is being disregarded entirely and the write-host $contentType.Name is firing for every list in the foreach block. What is wrong with the if statement?

function PopulateData($web, $includeFileSize) {
         Write-Host "Current Site " $web.url -ForegroundColor Cyan 
         #$libs = Get-PnPList -Web $web | Select-Object AllowContentTypes | Where-Object{($_.AllowContentTypes -eq $true)}
         $libs = Get-PnPList -Web $web | Where-Object{($_.BaseType -eq 1)}
         foreach($lib in $libs) {
         write-host "Library Title ############# " $lib.Title
         $ContentTypes = Get-PnPContentType -List $lib

            foreach($contentType in $ContentTypes) {

                if($contentType.Name -eq 'Knowledge Document' -or 'TELL Document') {
                write-host $contentType.Name

            }
         } 
    }
}
1
  • needs to be if(($contentType.Name -eq 'Knowledge Document') -or ($contentType.Name -eq 'TELL Document')) Jul 17, 2019 at 12:15

1 Answer 1

1

Try using below code block:

foreach($contentType in $ContentTypes) {
    if($contentType.Name -eq 'Knowledge Document' -Or contentType.Name -eq 'TELL Document') {
        write-host $contentType.Name
    }
}

See examples given in below article for more clarification:

PowerShell Basics: If -And & If -Or Statements.

Your Answer

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

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