none
SP 2016 - PowerShell - Farm Wide List of a Deactivated Content Type

    Question

  • Hello Community,

    I have a user request to determine everywhere in the Farm where a particular content type is deactivated.  Naturally I want to use PowerShell, and I have the script below as a starting point (thank you SharePoint Diary), but this script lists all deactivated content types (which is way too much!).  Can anyone help me modify this to only look for a particular Content Type?  Please provide code examples and guidance.

    Thanks!

    Tom

    dd-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue
     
    $InactiveFeatures = @()
     
    #Get All installed features on respective scopes
    $WebAppFeatures =  Get-SPFeature | Where-Object {$_.Scope -eq "WebApplication" }
    $siteFeatures = Get-SPFeature | Where-Object {$_.Scope -eq "Site" } 
    $WebFeatures = Get-SPFeature| Where-Object {$_.Scope -eq "Web" }
     
    Write-host "Checking Web Application Scoped Features..."
       foreach ($WebAppFeature in $WebAppFeatures)
       {
           $Flag = $False
           foreach ($WebApp in Get-SPWebApplication)
        {
             if ((Get-SPFeature -WebApplication $WebApp.URL | Where-Object {$_.Id -eq $WebAppFeature.id}) -ne $null)
             {
              #We found that the Feature is active, Lets end up the loop
        $Flag = $True
        break 
             }
      }
      if($Flag -eq $False)
      {
       Write-Host "$($WebFeature.DisplayName) is not Active on any Web Application!)"
      }
        
       }
     
       Write-Host "`nChecking Site Collection Scoped Features..."
       foreach ($SiteFeature in $SiteFeatures)
       {
           $Flag = $False
           :WebAppLoop1 foreach ($WebApp in Get-SPWebApplication)
        {
          foreach($site in $WebApp.Sites)
       {
              if ((Get-SPFeature -Site $Site.URL | Where-Object {$_.Id -eq $SiteFeature.id}) -ne $null)
              {
               #We found that the Feature is active, Lets end up the loop
         $Flag = $True
         break WebAppLoop1 
              }
       }
      }
       if($Flag -eq $False)
       {
        Write-Host "$($SiteFeature.DisplayName) is not Active on Any Site Collection!"
       }   
       }
     
     Write-host "`nChecking Web Scoped Feature..."
       foreach ($WebFeature in $WebFeatures)
       {
           $Flag = $False
        #I'm limiting to a single web application, Remove ""http://sharepoint.crescent.com" to process all WebApps
           :WebAppLoop2 foreach ($WebApp in Get-SPWebApplication "http://sharepoint.crescent.com")
        {
             foreach($Site in $WebApp.Sites)
       {
           foreach($Web in $Site.AllWebs)
        {
               if ((Get-SPFeature -Web $Web.URL | Where-Object {$_.Id -eq $WebFeature.id}) -ne $null)
               {
                #We found that the Feature is active, Lets end up the loop
          $Flag = $True
          break WebAppLoop2 
               }
        }
       }
         }
       if($Flag -eq $False)
       {
        Write-Host "$($WebFeature.DisplayName) is not Active on Any Web!"
       }   
     }
    
    
    #Read more: http://www.sharepointdiary.com/2014/02/find-all-inactive-features-in-sharepoint-using-powershell.html#ixzz5oBNsnoOW


    Tom Molskow - Senior SharePoint Architect - Microsoft Community Contributor 2011 and 2012 Award - Linked-In - SharePoint Gypsy

    Friday, May 17, 2019 12:06 PM

Answers

  • @ Dennis - this also works, just gives all inactive features

    cls
    
    $siteFeatures = Get-SPFeature | Where-Object {$_.Scope -eq "Site" } # Farm, WebApp, Site and Web
    if ($siteFeatures -ne $null)
    {
    	foreach ($feature in $siteFeatures)
    	{
    		# -Site can be replace by -Farm (without url), -WebApp, -Web
    		if ((Get-SPFeature -Site https://myspsite | Where-Object {$_.Id -eq $feature.id}) -eq $null)
    		{
    			# Inactive feature
    			Write-Host "$($feature.Scope) feature $($feature.DisplayName) " -ForeGroundColor Yellow
    		}
    	}
    }


    Tom Molskow - Senior SharePoint Architect - Microsoft Community Contributor 2011 and 2012 Award - Linked-In - SharePoint Gypsy


    Thursday, May 23, 2019 6:46 PM

All replies

  • Hi,

    The following PowerShell for your reference.

    Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue
    $WebAppFeatureName = "TaxonomyTimerJobs"
    $SiteFeatureName = "SiteHelp"
    $WebFeatureName = "MySiteNavigation"
    #Get All installed features on respective scopes
    $WebAppFeature =  Get-SPFeature | Where-Object {$_.Scope -eq "WebApplication" -and $_.DisplayName -eq $WebAppFeatureName}
    $SiteFeature = Get-SPFeature | Where-Object {$_.Scope -eq "Site" -and $_.DisplayName -eq $SiteFeatureName} 
    $WebFeature = Get-SPFeature| Where-Object {$_.Scope -eq "Web" -and $_.DisplayName -eq $WebFeatureName}
    
    foreach ($WebApp in Get-SPWebApplication)
    {
    	if ((Get-SPFeature -WebApplication $WebApp.URL | Where-Object {$_.Id -eq $WebAppFeature.id}) -ne $null)
    	{
    		#We found that the Feature is active, Lets end up the loop
    		Write-Host "WebApplication: "$WebApp.URL
    	}
    	foreach($Site in $WebApp.Sites)
    	{
    		if ((Get-SPFeature -Site $Site.URL | Where-Object {$_.Id -eq $SiteFeature.id}) -ne $null)
    		{
    			Write-Host "Site: "$Site.URL
    		}
    		foreach($Web in $Site.AllWebs)
    		{
    			if ((Get-SPFeature -Web $Web.URL | Where-Object {$_.Id -eq $WebFeature.id}) -ne $null)
    			{
    				Write-Host "Web: "$Web.URL
    			}
    		}
    	}
    }
    

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, May 20, 2019 2:52 AM
    Moderator
  • Hey Dennis,

    I'll give that a try and LYK - thanks!

    Tom


    Tom Molskow - Senior SharePoint Architect - Microsoft Community Contributor 2011 and 2012 Award - Linked-In - SharePoint Gypsy

    Monday, May 20, 2019 3:37 PM
  • @Dennis - Hey Dennis either the script did not work or our farm is so large it never finished because I never saw any output.  Is there a way to trim it down to just look for a particular content type within one web application?

    Tom Molskow - Senior SharePoint Architect - Microsoft Community Contributor 2011 and 2012 Award - Linked-In - SharePoint Gypsy

    Tuesday, May 21, 2019 11:13 AM
  • Hi Tom,

    To make it work in one web application, modify the code as below.

    Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue
    $WebAppFeatureName = "TaxonomyTimerJobs"
    $SiteFeatureName = "SiteHelp"
    $WebFeatureName = "MySiteNavigation"
    #Get All installed features on respective scopes
    $WebAppFeature =  Get-SPFeature | Where-Object {$_.Scope -eq "WebApplication" -and $_.DisplayName -eq $WebAppFeatureName}
    $SiteFeature = Get-SPFeature | Where-Object {$_.Scope -eq "Site" -and $_.DisplayName -eq $SiteFeatureName} 
    $WebFeature = Get-SPFeature| Where-Object {$_.Scope -eq "Web" -and $_.DisplayName -eq $WebFeatureName}
    
    $WebApp=Get-SPWebApplication https://sitename
    
    if ((Get-SPFeature -WebApplication $WebApp.URL | Where-Object {$_.Id -eq $WebAppFeature.id}) -ne $null)
    {
    	#We found that the Feature is active, Lets end up the loop
    	Write-Host "WebApplication: "$WebApp.URL
    }
    foreach($Site in $WebApp.Sites)
    {
    	if ((Get-SPFeature -Site $Site.URL | Where-Object {$_.Id -eq $SiteFeature.id}) -ne $null)
    	{
    		Write-Host "Site: "$Site.URL
    	}
    	foreach($Web in $Site.AllWebs)
    	{
    		if ((Get-SPFeature -Web $Web.URL | Where-Object {$_.Id -eq $WebFeature.id}) -ne $null)
    		{
    			Write-Host "Web: "$Web.URL
    		}
    	}
    }
    

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Wednesday, May 22, 2019 8:34 AM
    Moderator
  • @Dennis - we're definitely close, but it returned nothing and yet I know there are several instances of the CTT I was searching on that are deactivated - should I be using the CTT display name or some other name?

    Tom Molskow - Senior SharePoint Architect - Microsoft Community Contributor 2011 and 2012 Award - Linked-In - SharePoint Gypsy

    Wednesday, May 22, 2019 11:54 AM
  • Hi,

    Please use the DisplayName of the feature in the PowerShell above.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, May 23, 2019 8:42 AM
    Moderator
  • @Dennis - Sorry, I just don't get anything back, but I now have something that's "on the way".  The script below does return all the active features per a web application, if you could help me modify this so it just gives a report on only one feature, and only when it's deactivated, that would be great.

     cls
    
    Add-PsSnapin Microsoft.SharePoint.PowerShell
        $webapp = "https://mytools"
    
    $results = @()
    
    $webapp | Get-SPSite -Limit All | % {
        $siteCol = $_.RootWeb.Url
        Get-SPFeature -Site $_ | % {
            $feature = $_; 
            $obj = New-Object PSObject;
            $obj | Add-Member NoteProperty Title $($feature.DisplayName);
            $obj | Add-Member NoteProperty Hidden $($feature.Hidden);
            $obj | Add-Member NoteProperty Url $($siteCol);
            $obj | Add-Member NoteProperty Type "Site Feature";
    
            $results += $obj;
        }
    
        $_.AllWebs | % {
             $web = $_.Url
             Get-SPFeature -Web  $_ -Limit All | % {
                $feature = $_; 
                $obj = New-Object PSObject;
                $obj | Add-Member NoteProperty Title $($feature.DisplayName);
                $obj | Add-Member NoteProperty Hidden $($feature.Hidden);
                $obj | Add-Member NoteProperty Url $($web);
                $obj | Add-Member NoteProperty Type "Web Feature";
    
                $results += $obj;
            }
        }
    }
    
    $results | export-csv -path D:\SPFeatures\features.csv -NoTypeInformation


    Tom Molskow - Senior SharePoint Architect - Microsoft Community Contributor 2011 and 2012 Award - Linked-In - SharePoint Gypsy

    Thursday, May 23, 2019 5:21 PM
  • @ Dennis - this also works, just gives all inactive features

    cls
    
    $siteFeatures = Get-SPFeature | Where-Object {$_.Scope -eq "Site" } # Farm, WebApp, Site and Web
    if ($siteFeatures -ne $null)
    {
    	foreach ($feature in $siteFeatures)
    	{
    		# -Site can be replace by -Farm (without url), -WebApp, -Web
    		if ((Get-SPFeature -Site https://myspsite | Where-Object {$_.Id -eq $feature.id}) -eq $null)
    		{
    			# Inactive feature
    			Write-Host "$($feature.Scope) feature $($feature.DisplayName) " -ForeGroundColor Yellow
    		}
    	}
    }


    Tom Molskow - Senior SharePoint Architect - Microsoft Community Contributor 2011 and 2012 Award - Linked-In - SharePoint Gypsy


    Thursday, May 23, 2019 6:46 PM
  • Hi Tom,

    Thanks for sharing.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, May 28, 2019 8:52 AM
    Moderator