Articles about European Sharepoint Hosting Service
SharePoint 2013 Hosting – HostForLIFE.eu :: Get Content Type Usage Details In SharePoint Using Powershell
This script will give you the usage details and dependencies of any content type, such as – list URL, Web URL, etc. and wherever that is being used. This might come in handy when you wish to delete the content types and you have to make sure of all its dependencies and references getting cleaned.
The output will be in the form of a CSV file where the above-mentioned content type is used. Input parameters used are:
Name of content type
Web Application URL
To get started, replace Content Type name and Web Application URL below with the one to be searched for,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
$myContentType = "Report Builder Report" $myWebApp = "http://myWebAppURL.com" if ((Get -PSSnapin "Microsoft.SharePoint.PowerShell" - ErrorAction SilentlyContinue) -eq $null) { Add -PSSnapin "Microsoft.SharePoint.PowerShell" } @results = @() $sites = Get -SPSite –Limit All –WebApplication $myWebApp try { foreach($site in $sites) { Write-Host "Looking in site– " $site.Url foreach($web in $site.AllWebs) { Write-Host $web.Url foreach($list in $web.lists) { foreach($ctype in $list.ContentTypes | ? { $_.Name –eq $myContentType}) { foreach($item in $list.Items | ? { $_.ContentType.Name –eq $myContentType }) { $RowDetails = @ { "List" = $list.Title "ListURL" = $list.DefaultView.Url "ContentType" = $item.ContentType.Name "Site" = $site.Url "Web" = $web.Url } $results += New-Object PSObject –Property $RowDetails break } } } $web.Dispose() } $site.Dispose() } } catch { $e = $_.Exception $line = $_.InvocationInfo.ScriptLineNumber $msg = $e.Message Write-Host –ForegroundColor Red "Caught Exception: $e at $line" Write-Host $msg Write-Host "Something went wrong" } $results | Export - CSV– Path C: \ContentTypeUsageReport.csv– NoTypeInformation Write-Host " === === === === === === === Completed! === === === === === === === === == " |
Print article | This entry was posted by Peter on January 18, 2018 at 5:22 am, and is filed under European SharePoint 2013 Hosting. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |