Replace document properties using powershell

Hello ,
I have document library. It has one column of categories. There are multiple categories tagged for many document .I want to replace some old categories with new one using powershell.
In other words, first i need to check if that item column has that property if yes replace it with new property. 
I dont want to change properties manually as this need checking out document. 
Please guide. powershell script will be helpful for me.

http://blogs.msdn.com/b/paulking/archive/2011/10/04/using-powershell-scripts-to-modify-document-properties-in-sharepoint-2010.aspx
# 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,idOr try http://sharepoint.stackexchange.com/questions/78084/how-to-update-document-meta-data-using-powershell$listItem = $web.GetListItem($file.ServerRelativeUrl);
$listItem.File.Checkout();
$listItem.Properties['My Cust Prop 1'] = 30
$listItem.Properties['My Cust Prop 2'] = '2012-10-25T00:00:00Z'
$listItem.Update();
$listItem.File.Checkin('Updated')http://sharepoint.stackexchange.com/questions/61159/get-document-properties-keys-valuehttp://social.technet.microsoft.com/Forums/ro-RO/db9191e4-c1b6-4d4b-aa58-a352da1839fc/powershell-script-to-create-document-libraries-with-specific-properties?forum=sharepointadminprevious
If this helped you resolve your issue, please mark it Answered

Similar Messages

  • How to update managed metadata column for all file in document library using powershell

    Hi,
    How to update managed metadata column for all file in document library using powershell?
    Any help on it.
    Thanks & REgards
    Poomani Sankaran

    Hi TanPart,
    I have changed the code which you have give in order to get the files from SharePoint 2010 Foundation  Document Library.But i am getting below error in powershell.
    Property 'ListItemCollectionPosition' cannot be found on this object; make sure it exists and is settable.
    Could you tell me which is the issues in it?
    See the code below.
    $web = Get-SPWeb http://ntmoss2010:9090/Site
    $list = $web.Lists["DocLib"]
    $query = New-Object Microsoft.SharePoint.SPQuery
    $query.ViewAttributes = "Scope='Recursive'";
    $query.RowLimit = 2000
    $caml = '<Where><Contains><FieldRef Name="Title" /><Value Type="Text">Process Documents/Delivery</Value></Contains></Where>' +
            '<OrderBy Override="TRUE"><FieldRef Name="ID"/></OrderBy>'
    $query.Query = $caml
    do
        $listItems = $list.GetItems($query)
        $spQuery.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
        foreach($item in $listItems)
            #Cast to SPListItem to avoid ambiguous overload error
            $spItem = [Microsoft.SharePoint.SPListItem]$item;
            Write-Host $spItem.Title       
    while ($spQuery.ListItemCollectionPosition -ne $null)
    Thanks & Regards
    Poomani Sankaran

  • How to rename content type on web site level and underneath all the document libraries using powershell?

    Hello
    I wantto rename content type on web site level and underneath all the document libraries using powershell, please let me know how can do this?
    I saw this url
    http://suryapulipati.blogspot.in/2011/08/rename-content-type-name-in-list-using.html, but I want to change everything from Web Site, subsite and underneath document libraries. Because if you try to change on any on document library, it will be applicable
    for that document library, if you change on web level then underneath document libraries content type names not updated automatically.
    Please advise
    Avi

    Not sure with powershell.
    I could help you out with Server Side or Web Services though.
    Brandon James SharePoint Developer/Administrator

  • Update document library item where a docx document uploaded using powershell script

    HI
    when i update an existing item of a document library using script i faced the issue.
    i uploaded two .txt files and two word docx files and a png file.
    where i update .txt file item there is no issues , but  for other items i have problem.
    PS C:\Scripts> C:\Scripts\UPdateDocLibrary.ps1
    Exception calling "Update" with "0" argument(s): "There is no file with URL 'Do
    cs/Emc.docx' in this Web."
    At C:\Scripts\UPdateDocLibrary.ps1:26 char:13
    + $item.Update <<<< ()
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException
    Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
    $webURL = "http://tspmcwfe:89"
    $listName = "Docs"
    #Get the SPWeb object and save it to a variable
    $web = Get-SPWeb $webURL
    #Get the SPList object to retrieve the "Demo List"
    $list = $web.Lists[$listName]
    $items = $list.items
    #Go through all items
    foreach($item in $items)
    if($item["NO"] -eq $null)
    $item["Title"] = "My updated edited item!"
    $item.Update()
    adil

    Please check if file is checkout or locked , and if not then checkout it and then try to update -
    $url= $webURL + $item.File.Url;
    $file = $web.GetFile($url);
    if($file.CheckOutType -eq "None" -And $file.LockType -eq "None")
    $file.CheckOut();
    also please try these option, may help -
    1. Allow unsafe update at web
    $web.AllowUnsafeUpdates=$true;
    2. try systemupdate
    $item.SystemUpdate($false)
    Thanks
    Ganesh Jat [My Blog |
    LinkedIn | Twitter ]
    Please click 'Mark As Answer' if a post solves your problem or 'Vote As Helpful' if it was useful.

  • Is it possible to get Exchange emails downloaded to SharePoint document library using Powershell and or Custom Workflow?

    I have been asked to see if it would be possible to get  exchange emails downloaded and or sent to a document library .
    I know of the sitemail box app. but we are not running Exchange 2013.
    and setting up the lists and or document library to receive emails using the built in doesn't seem to be working...( maybe not configured correctly, i would need to see what the prior admin/developer did)
    But is there a way to get the emails downloaded to a document library using a workflow and or a powershell script that is triggered via  workflow?

    Hi,
    Since workflow can only work on items in SharePoint sites, they cannot get Exchange emails, let alone download emails to SharePoint library. However, you could manually save email to local and upload it to SharePoint list/library.
    I'd suggest you toubleshooting the incoming email settings in SharePoint. Please refer to the article below and check your configuration:
    https://technet.microsoft.com/en-us/library/cc262947.aspx
    http://blogs.technet.com/b/harmeetw/archive/2012/12/29/sharepoint-2013-configure-incoming-emails-with-exchange-server-2013.aspx
    Regards,
    Rebecca Tu
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • How to get SharePoint Search and offline Availability properties using powershell with CSOM

    Hi,
    I want to get the information about the SharePoint sites being crawled or not. I tried to get "Search
    and offline Availability in SharePoint" settings properties but I couldn't get those properties.
    I
    followed below thread with no luck : http://www.c-sharpcorner.com/uploadfile/anavijai/search-and-offline-availability-in-sharepoint-2010/
    I couldn't find $web.AllowAutomaticASPXPageIndexing property at site level
    but i can see $list.NoCrawl at list level.
    Can any body help me out to get those values?
    Any help would be greatly appreciated.
    Thank you.
    AA.

    Hi,
    Since AllowAutomaticASPXPageIndexing is a member in SPWeb members while not in Web members, we can not use Client Side Object Model with it. If you need to use it in client side, you need to create a web service for it.
    https://msdn.microsoft.com/EN-US/library/microsoft.sharepoint.client.web_members.aspx
    https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb_members.aspx
    Regards,
    Rebecca Tu
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • How to upload a document with values related to document properties in to document set at same time using Javascript object model

    Hi,
          Problem Description: Need to upload a document with values related to document properties using custom form in to document set using JavaScript Object Model.
        Kindly let me know any solutions.
    Thanks
    Razvi444

    The following code shows how to use REST/Ajax to upload a document to a document set.
    function uploadToDocumentSet(filename, content) {
    appweburl = decodeURIComponent(getQueryStringParameter('SPAppWebUrl'));
    hostweburl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
    var restSource = appweburl +
    "/_api/SP.AppContextSite(@target)/web/GetFolderByServerRelativeUrl('/restdocuments/testds')/files/add(url='" + filename + "',overwrite=true)?@target='" + hostweburl + "'";
    var dfd = $.Deferred();
    $.ajax(
    'url': restSource,
    'method': 'POST',
    'data': content,
    processData: false,
    timeout:1000000,
    'headers': {
    'accept': 'application/json;odata=verbose',
    'X-RequestDigest': $('#__REQUESTDIGEST').val(),
    "content-length": content.byteLength
    'success': function (data) {
    var d = data;
    dfd.resolve(d);
    'error': function (err,textStatus,errorThrown) {
    dfd.reject(err);
    return dfd;
    Then when this code returns you can use the following to update the metadata of the new document.
    function updateMetadataNoVersion(fileUrl) {
    appweburl = decodeURIComponent(getQueryStringParameter('SPAppWebUrl'));
    hostweburl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
    var restSource = appweburl +
    "/_api/SP.AppContextSite(@target)/web/GetFolderByServerRelativeUrl('/restdocuments/testds')/files/getbyurl(url='" + fileUrl + "')/listitemallfields/validateupdatelistitem?@target='" + hostweburl + "'";
    var dfd = $.Deferred();
    $.ajax(
    'url': restSource,
    'method': 'POST',
    'data': JSON.stringify({
    'formValues': [
    '__metadata': { 'type': 'SP.ListItemFormUpdateValue' },
    'FieldName': 'Title',
    'FieldValue': 'My Title2'
    'bNewDocumentUpdate': true,
    'checkInComment': ''
    'headers': {
    'accept': 'application/json;odata=verbose',
    'content-type': 'application/json;odata=verbose',
    'X-RequestDigest': $('#__REQUESTDIGEST').val()
    'success': function (data) {
    var d = data;
    dfd.resolve(d);
    'error': function (err) {
    dfd.reject(err);
    return dfd;
    Blog | SharePoint Field Notes Dev Tools |
    SPFastDeploy | SPRemoteAPIExplorer

  • Split large .pptx file to multiple files using PowerShell

    Hi.
    I'm not a programmer and I have the task to split big .pptx file(>100 slides) to multiple .pptx files with 4 slides in each one and save them into SP library. It should be done on PowerShell.
    Thanks for any help!

    Hi,
    For splitting PowerPoint files into multiple parts, I would suggest you post this question to Office forum, you will get more help and confirmed answers there:
    http://social.technet.microsoft.com/Forums/office/en-US/home
    For uploading files to SharePoint Library using PowerShell, here are some links with script demos provided for your reference:
    http://social.technet.microsoft.com/wiki/contents/articles/19529.sharepoint-2010-upload-file-in-document-library-using-powershell.aspx
    http://spfileupload.codeplex.com/
    Best regards
    Patrick Liang
    TechNet Community Support

  • What happened to the Initial View options under Document Properties??

    What happened to the Initial View options under Document Properties? I just updated my Reader and it's no longer accessible! SOS.

    Hi kga406,
    Please tell me if you are able to access 'initial view' tab in document properties using Acrobat.
    You can change initial view settings only in Acrobat and can view PDFs in Reader with the same initial view as set.
    Regards,
    Anubha

  • Use Powershell to replace text with image in Word document

    I have a powershell script that uses a Word document as a template to create signatures that I am pushing out to my organization.
    The document is populated with text formatted the way I want the signature to look, that I then do a FindText and ReplaceText on.  This works fine for replacing text with text, but I can't figure out how to properly replace some of the holder text with
    an image and a link.  I found a few posts about adding images to word documents, but none that seem to work properly in this scenario.
    Any insight would be greatly appreciated, thanks!

    Dear BOFH,
    You are correct that method I outlined is not for inserting an image into a signature block (which would be in Outlook, not Word).  The links you post do certainly deal with outlook signatures, well done... Except that the question was about how to
    use a Powershell script to replace text in a Word document with an image.  Sure it was framed in the context of creating signatures, but the poster expressed that they already had a method of generating and replacing text, and just needed to know, as
    I did, how to do the thing they actually asked.
    Please BOFH... Please forgive my audacity in hoping to find a reference (any reference) to how to replace Word text with images via Powershell in a thread titled "Use Powershell to replace text with image in Word document".
    This is certainly a scripting question, and even something as simple as "You will need to call the .NET methods for the Word find/replace functionality.  Please ask in the Word forums for the correct method to use. 
    If you need help on calling .NET methods look HTTP ://here"support you offered combined with the contempt you offer in response to my actual substantive help to the actual question asked.
    BOFH, you are not better than us, just more arrogant.
    Can you please start your own question as this one has been closed.  Please see scripting guidelines.
    We cannot guarantee you satisfaction as this is a user supported forum.  The is no SLA for community support.  Perhaps if you posted a better worded question as a new topic someone might be able to help you resolve your issue.
    The topic you are posting on is closed and answered.
    ¯\_(ツ)_/¯

  • How to get Document Set property values in a SharePoint library in to a CSV file using Powershell

    Hi,
    How to get Document Set property values in a SharePoint library into a CSV file using Powershell?
    Any help would be greatly appreciated.
    Thank you.
    AA.

    Hi,
    According to your description, my understanding is that you want to you want to get document set property value in a SharePoint library and then export into a CSV file using PowerShell.
    I suggest you can get the document sets properties like the PowerShell Command below:
    [system.reflection.assembly]::loadwithpartialname("microsoft.sharepoint")
    $siteurl="http://sp2013sps/sites/test"
    $listname="Documents"
    $mysite=new-object microsoft.sharepoint.spsite($siteurl)
    $myweb=$mysite.openweb()
    $list=$myweb.lists[$listname]
    foreach($item in $list.items)
    if($item.contenttype.name -eq "Document Set")
    if($item.folder.itemcount -eq 0)
    write-host $item.title
    Then you can use Export-Csv PowerShell Command to export to a CSV file.
    More information:
    Powershell for document sets
    How to export data to CSV in PowerShell?
    Using the Export-Csv Cmdlet
    Thanks
    Best Regards
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • How to replace document edit-properties buttons

    We have replaced the "Edit Properties" ribbon button with the following element XML:
    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <CustomAction
    Sequence="20"
    Location="CommandUI.Ribbon"
    RegistrationId="101"
    RegistrationType="List"
    Title="New EditProperties">
    <CommandUIExtension>
    <CommandUIDefinitions>
    <CommandUIDefinition Location="Ribbon.Documents.Manage.EditProperties">
    <Button Id="Ribbon.Documents.Manage.EditProperties.ReplacementButton"
    Command="MyNewButtonCommand"
    Image16by16="/_layouts/$Resources:core,Language;/images/formatmap16x16.png" Image16by16Top="-128" Image16by16Left="-224"
    Image32by32="/_layouts/$Resources:core,Language;/images/formatmap32x32.png" Image32by32Top="-128" Image32by32Left="-96"
    LabelText="$Resources:core,ButEditProperties;"
    ToolTipTitle="$Resources:core,ButEditProperties;"
    ToolTipDescription="$Resources:core,cui_STT_ButEditDocumentProperties;"
    TemplateAlias="o1"
    />
    </CommandUIDefinition>
    </CommandUIDefinitions>
    <CommandUIHandlers>
    <CommandUIHandler Command="MyNewButtonCommand" CommandAction= "Javascript:
    function demoCallback(dialogResult, returnValue)
    SP.UI.Notify.addNotification('Operation Successful!');
    SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
    var ctx = SP.ClientContext.get_current();
    var items = SP.ListOperation.Selection.getSelectedItems(ctx);
    var myItems = '';
    var k;
    for (k in items)
    myItems += '|' + items[k].id;
    var options = {
    url: '/_layouts/DCMLibrarySettings/LibraryDcmSetting.aspx?List={01610989-0039-4cbe-9890-38d685af0334}',
    tite: 'Set Document Properties',
    allowMaximize: true,
    showClose: false,
    width: 800,
    height: 600,
    dialogReturnValueCallback: demoCallback };
    SP.UI.ModalDialog.showModalDialog(options);" />
    </CommandUIHandlers>
    </CommandUIExtension>
    </CustomAction>
    </Elements>
    However, we are unsure how to repeat this for the following document "Edit properties" option:
    Can anyone tell us where to find the XML definition for this please?

    Hi,
    Here is a workaround for your reference:
    We can add a new ECB Menu use the following XML definition.
    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <CustomAction
    Id="ReplaceEditProperties"
    RegistrationType="List"
    RegistrationId="101"
    ImageUrl="/_layouts/images/edititem.gif"
    Location="EditControlBlock"
    Sequence="220"
    Title="Replace Edit Properties" >
    <UrlAction Url="javascript:alert('Test')"/>
    </CustomAction>
    </Elements>
    Then hide the old "Edit Properties" option using CSS, add the following Style into a Content Editor Web Part.
    <style>
    LI[text='Edit Properties'] {
    DISPLAY: none !important
    </style>
    More information:
    http://www.thespgeek.com/2011/01/how-to-add-custom-menu-item-in.html
    Best Regards,
    Dennis Guo
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Replace Part of DisplayName Using PowerShell

    Hello,
    I am trying to replace part of a display name using powershell. For example, our display names look like this:
    "Lname, Fname/Department"
    I'm trying to replace only the department, basically what is after the /, from "Information Systems" to "IT"
    Here's what I have but it is failing:
    Get-ADUser "ex10testertesters" | % { Set-AdUser $_ -DisplayName ($_.Displayname -replace 'Information Systems$','IT') }
    Error I am getting is below:
    Set-ADUser : replace
    At line:1 char:48
    + Get-ADUser "test" | % { Set-AdUser <<<<  $_ -DisplayName ($_.Dis
    playname -replace '/Information Systems','IT') }
        + CategoryInfo          : InvalidOperation: (CN=ex10tester...DC=company,DC
       =com:ADUser) [Set-ADUser], ADInvalidOperationException
        + FullyQualifiedErrorId : replace,Microsoft.ActiveDirectory.Management.Com
       mands.SetADUser
    Can anyone assist in what the issue is? Thank you!

    DisplayName is not a default attribute returned by Get-ADUser; you'll need to specify it.
    Get-ADUser "ex10testertesters" -Properties 'DisplayName' | % {
    $newDisplayName = $_.Displayname -replace 'Information Systems$','IT'
    Set-AdUser $_ -DisplayName:$newDisplayName

  • Search and Replace text in file using PowerShell

    I want to schedule a script in PowerShell to search a directory for an XML file for a particular text string and replace it with a different text string and then save the file with the same name, the name of the file
    will change each time the script is run on a daily basis. There will only be one XML file in the location when the scheduled script is run.
    I have never used PowerShell but am familiar with batch file commands, can anyone please help!!
    KevinS

    Hi Kevin,
    I’m writing to just check in to see if the suggestions were
    helpful. If you need further help, please feel free to reply this post directly so we will be notified to follow it up.
    If you have any feedback on our support, please
    click here.
    Best Regards,
    Anna
    TechNet Community Support

  • Uploading document using Powershell is throwing error- There is no file with URL

    Hi.
    I am trying to upload multiple documents to a sub folder in a library using powershell.
    I am getting the error as : ForEach-Object : Exception calling "Add" with "3" argument(s):
    "<nativehr>0x80070003</nativehr><nativestack></nativestack>There is no file
    with URL 'server/TestLibrary/User_image/ab_3f_wht_ist_small_gif.gif' in this Web."
    I have used the below code:
    function UploadImages($weburl)
    $docLibraryName = "TestLibrary"
    $localFolderPath = "C:\Users\Imgs\user_image"
    Add-PsSnapin Microsoft.SharePoint.PowerShell -erroraction silentlycontinue
    $web = Get-SPWeb -Identity $webUrl
    $docLibrary = $web.Lists[$docLibraryName]
    $subFolderName="user_image"
    Add-PsSnapin Microsoft.SharePoint.PowerShell -erroraction silentlycontinue
    $web = Get-SPWeb -Identity $webUrl
    $docLibrary = $web.Lists[$docLibraryName]
    #Attach to local folder and enumerate through all files
    $files = ([System.IO.DirectoryInfo] (Get-Item $localFolderPath)).GetFiles() | ForEach-Object {
    #Create file stream object from file
    $fileStream = ([System.IO.FileInfo] (Get-Item $_.FullName)).OpenRead()
    $contents = new-object byte[] $fileStream.Length
    $fileStream.Read($contents, 0, [int]$fileStream.Length);
    $fileStream.Close();
    write-host "Copying" $_.Name "to" $docLibrary.Title "in" $web.Title "..."
    #Add file
    $folder = $web.getfolder($docLibrary.Title + "/" + $subFolderName)
    write-host "folder is " $folder
    $spFile = $folder.Files.Add($folder.Url + "/" + $_.Name, $contents, $true)
    $spItem = $spFile.Item
    Write-Host -f Green "Added Images to Library !!!"
    $web.Dispose()
    How to fix this?
    Thanks

    HI,
    Is the name of the image or the sub folder name the issue?
    I have the images with the name as "ab_3f_wht_ist_small_gif.gif".  folder name "User_image"
    There are underscores on the file name, but there is no space. When I add the file from the library (using the UI), the image is getting added.
    But adding through the powershell is giving the issue.
    I have checked this:
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/e810ad03-81ef-4fa6-aab8-ddc896a13ebf/getting-error-during-uploading-a-document-using-powershell?forum=sharepointdevelopmentprevious
    but did not help.
    Thanks

Maybe you are looking for

  • Immediate Transfer Order Creation not occuring for Sales Document Type

    Hello gurus, I have a situation where a transfer order is not being created immediately for a specific sales document type. Here is an example document flow of a desired scenario where the system is working: Sales document type:  ZOR >  Delivery type

  • Appending XML Node to XMLTYPE Variable

    Hi All, My Database Details, BANNER Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production PL/SQL Release 9.2.0.1.0 - Production CORE 9.2.0.1.0 Production TNS for 32-bit Windows: Version 9.2.0.1.0 - Production NLSRTL Version 9.2.0.1.0 - Productio

  • Error occurs during configuration of ESR in CE

    I'm doing the "Configuration of ESR in CE" senario in the NWA. In the final step: Importing XI content following error happened: Error: Password cannot be null or empty and I found following exception in log: importContentInput <importContentInput> <

  • How to cancell the invoice

    Hi friends Pls suggest me how to can cell the invoice once it is got generated, Regards Sreenivas

  • Exporting report devloped through Jdevloper to PDF

    Hi We need a way to export our reports that we devloped through Oracle Jdevloper using BI Beans to PDF.Its giving optios to export it to Excel,CSV and tabbed Format. Can we export these reports into PDF format??