2

I had written the below code to ignore the statements based on if condition, But find no luck. Can any one do let me know what's wrong in my below code

$myListColl = $eachWeb.Lists;
$mylistsToIgnore=101
foreach ($eachList in $oListColl)
{
   if($mylistsToIgnore==$eachList.TempladID)
    {
     //Ignore statement
    }
    else 
    {
    //Other Statement
    }

} 
5

For starters, you compare on the wrong property (and you are not using a PowerShell compare operator):

Change

if($mylistsToIgnore==$eachList.TempladID)

to

if($mylistsToIgnore -eq $eachList.TemplateID)

Also, another typo:

Change

foreach ($eachList in $oListColl)

to

foreach ($eachList in $myListColl)
  • On Break point I don't get any value of below line , But it is showing condition as right $templateid= $eachList.TemplateID – MSA Jul 21 '17 at 10:52
3

There is no TemplateId property in SPList object. You have to find it by TemplateFeatureId in SPWeb.ListTemplates.

$myListColl = $eachWeb.Lists
$mylistsToIgnore = @(101)

foreach ($eachList in $myListColl)
{
    $listTemplate = $eachWeb.ListTemplates | ? {$_.FeatureId -eq $eachList.TemplateFeatureId}
    if ($mylistsToIgnore.Contains($listTemplate.Type_Client))
    {
        # Ignore statement
    }
    else 
    {
        # Other Statement
    }
}

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.