Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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()  
share|improve this answer
    
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? –  kamleshrao Jun 10 '10 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 –  Ari Bakker Jun 10 '10 at 9:30
    
Can you please send the complete URL of dmirtysotnikov –  kamleshrao Jun 10 '10 at 11:25
    

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.