PowerShell Site Column Usage and Find Site Columns in List

PowerShell code to find the usage of a site column.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Web URL - site where the site column is defined or available
$WebURL = "http://site_url"

#Site URL - site collection
$SiteURL = "http://site_collection_url"

#Column to search - internal name
$ColumnInternalName = "internal_name_site_column"

#Get the Site
$Site = Get-SPSite $SiteURL

#Get the Web
$Web = Get-SPWeb $WebURL

#Get the Column
$column = $Web.AvailableFields.GetFieldByInternalName($ColumnInternalName)

#Find all List usages of the column
$WebColumnUsages = $column.ListsFieldUsedIn() #Gets the WebID & ListID values

#Get the lists where the site column is being used
foreach( $Usage in $WebColumnUsages )

    {
        $Site.AllWebs | foreach {$_.Lists} | where {$_.ID –eq $Usage.ListID } | Select Title, ParentWebURL, RootFolder
    }

PowerShell code to list all non hidden column of a list and indicate the ones that are site columns.

$w = Get-SPWeb "http://site_url"
$l = $w.GetList("http://list_url")

foreach ($field1 in $l.Fields | where {$_.Hidden -eq $false} | sort title ) {

Write-Host -NoNewline $field1.Title " - " $field1.InternalName 

	foreach ($field2 in $w.AvailableFields) {

	if ($field1.id -eq $field2.id) { 

	Write-Host -NoNewline " - SITE COLUMN"
	} 

	}
Write-Host " "
}

Some references:

http://social.technet.microsoft.com/wiki/contents/articles/15894.sharepoint-2010-interacting-with-site-columns-using-powershell.aspx

http://www.sharepointdiary.com/2014/01/find-sharepoint-site-column-usage-report.html

http://sharepoint.findincity.net/view/63539928672422258233910/is-it-possible-to-iterate-all-lists-in-sharepoint-in-search-for-a-given-field

http://techtrainingnotes.blogspot.ca/2012/10/sharepointfinding-column-display-and.html

Please vote:

http://sharepoint.uservoice.com/forums/282887-customer-feedback-for-sharepoint-server/suggestions/7553676-site-columns-display-where-used

http://sharepoint.uservoice.com/forums/282887-customer-feedback-for-sharepoint-server/suggestions/7239594-distinguish-a-site-column-from-a-list-column-in-a

Lire: Où sont utilisés les colonnes de sites et les types de contenu? Pour les mettre à jour ou supprimer

Advertisements

Laisser un commentaire

Entrer les renseignements ci-dessous ou cliquer sur une icône pour ouvrir une session :

Logo WordPress.com

Vous commentez à l’aide de votre compte WordPress.com. Déconnexion / Changer )

Image Twitter

Vous commentez à l’aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l’aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l’aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s