Posts Tagged 'lists'

Finding out where a list column is used in a site collection

There are times when you need to know where a specific list column is being used in your site collection. This is especially true for custom columns that you may have created. The following script can be used to find which lists are using a specific column name. (I posted this script on the SharePoint TechNet forum in response to a question.)


[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c") | out-null

[void][System.reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

# set-up working variables...

# Enter your SharePoint site collection URL here...

$TargetSiteUrl = "http://sharepoint_site_collection_URL"

# Enter the list column name you want to find here...

$FieldToFind = "Title"

# Starting search

write-host "FieldName, ListName, ListURL"

$spSite = new-object Microsoft.SharePoint.SPSite($TargetSiteUrl)

$colWebsites = $spSite.AllWebs

foreach ($web in $colWebsites)
{

$colLists = $web.Lists

foreach ($list in $colLists)
{

$fields = $list.Fields

foreach ($item in $fields)
{

If ($item.Title.Contains($FieldToFind))
{
write-host  $item.Title, ";", $list.Title, ";", $list.DefaultViewUrl
}

}

}

}

write-host "Finished."

How to delete all items in a list (using Powershell)

This week, I needed to find a way to efficiently delete all items in a SharePoint list, with the least amount of customization and development effort. I found some code on the Internet (such as here). You can also use SP Designer, or download a custom webpart called SPPurgeList (see here).

Well, I wanted to do it via Powershell (for a number of reasons). Here’s the code that I came up with (and which works on my farm).

This Powershell script iterates through and deletes all items in the specified list.

# script starts here…

[System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”) | out-null

$oContentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService;

[Microsoft.SharePoint.Administration.SPWebApplicationCollection]$waColl = $oContentService.WebApplications;

$siteUrl = “ENTER YOUR SITE URL HERE”

$webName = “ENTER YOUR SUBWEB HERE”

$spSite = new-object Microsoft.SharePoint.SPSite($siteurl)

$spWeb = $spSite.OpenWeb($webName)

$spList = $spWeb.Lists[“ENTER YOUR LIST NAME HERE”]

foreach ($item in $spList.items)
{

$deaditem=$splist.GetItemById($item.ID)
$deaditem.Delete()

}

# Finished!


RSS Information Week Headlines

  • An error has occurred; the feed is probably down. Try again later.

RSS SharePoint Team Blog

  • An error has occurred; the feed is probably down. Try again later.

RSS InfoPath Team Blog

  • An error has occurred; the feed is probably down. Try again later.

RSS Joel Oleson Blog

  • An error has occurred; the feed is probably down. Try again later.

RSS Bud Ratliff blog

  • An error has occurred; the feed is probably down. Try again later.

RSS Susan Hanley’s KM Blog

  • An error has occurred; the feed is probably down. Try again later.

Blog Stats

  • 401,897 hits