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 have document library. I want to replace some document properties using powershell. There are multiple properties associated with each document. First I'll need to check for all documents if that document has that properties (metadata) and if yes need to replace that with new one. Any ideas? scripts?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

here is powershell script to list all properties and then how to change them.

# Load SharePoint library
 [system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint")

 # Connect to the site collection http://SP2010 and store the object in the $site variable
 $site = New-Object Microsoft.SharePoint.SPSite("http://SP2010")

 # Connect to the root site in the site collection and store the object in $root
 $root = $site.rootweb

 # Store the Shared Documents document library in a variable $Docs
 $docs = $root.lists["Shared Documents"]

 # Display all the documents, their titles, names and IDs
 $docs.items | format-table -property title,name,id

 # Updates the title for each item in the list with Name
 $docs.items | ForEach { $_["Title"] = $_["Name"]; $_.Update() }

 # Display all the documents, their titles, names and IDs
 $docs.items | format-table -property title,name,id

http://blogs.msdn.com/b/paulking/archive/2011/10/04/using-powershell-scripts-to-modify-document-properties-in-sharepoint-2010.aspx

share|improve this answer
    
thank you. I got hint from this. Thanks again. –  Rajeev K Jun 19 at 9:48

Try the following script:

$web = Get-SPWeb http://YourServer/ListLocation
    $list = $web.Lists["TheList"]

    foreach ($item in $list.Items)
    {
    if( $list.Fields.ContainsField("ddlTest") -eq $true)
                   { 
      $item["Number"] = Get-Random -Min 0 -Max 100;
      $item.Update();
    }
    }
share|improve this answer

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.