5

I am new to PowerShell and would like to achieve the following tasks on a SharePoint 2010 Document library:

1) Using PowerShell, how can I display the List of Documents in a simple Document Library.

2) While traversing through the documents list, how can I modify the value of a custom added column in the Document Library?

1 Answer 1

5

Here's a simple example of how to display and update the 'title' field that could be modified slightly to achieve this:

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

$site = new-object Microsoft.SharePoint.SPSite("http://intranet")                                                        
$web = $site.rootweb                                                                                                

$list = $web.Lists["Documents"] 

foreach ($listItem in $list.Items)
{
    #display the filename of the document
    write-host $listItem.Name

    #update the title field to the filename
    $listItem["Title"] = $listItem["Name"]
    $listItem.Update()
}

$web.Dispose()
$site.Dispose()  
4
  • This is great. It worked on my SPS2010. I require some more inputs further: 1) Can you clarify if this is the old method which can be applied on MOSS 2007 list too? 2) Will the above script run from a Client workstation 3) Are there any better ways to achieve this using SharePoint 2010 PowerShell CommandLets? Commented Jun 10, 2010 at 4:42
  • 1) yes the method above should work on both SharePoint 2007 and 2010 as this part of the server object model (OM) hasn't changed. 2) To run scripts remotely you will need to use PowerShell remoting. 3) yep there are other neater ways to do this using the SharePoint 2010 Powershell Snapin - check out dmitrysotnikov.wordpress.com/2010/04/14/… for some tips Commented Jun 10, 2010 at 9:30
  • Can you please send the complete URL of dmirtysotnikov Commented Jun 10, 2010 at 11:25
  • dmitrysotnikov.wordpress.com/2010/04/14/… Commented Jun 10, 2010 at 12:28

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.