4

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?

3

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

6

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();
    }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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