none
Script to update a column with two fields (Powershell) RRS feed

  • Question

  • Hi,

    I am trying to update a column in all items in a document library via Powershell. The column is Name and it will updated with two combined existing fields Name and ID. The result is Name_ID. This is what I have so far. I think I am close but missing something

    $spWeb = Get-SPWeb -Identity http://www.google.com/
    $spsite = Get-SPSite -Identity http://www.google.com/test
    $spListItem [“FileName”] = $spListItem [“Name”]+$spListItem [“ID”]

    $spList = $spWeb.Lists[“Test Library”]

    foreach($item in $list.Items)
    {
    if($item["Name"] = "Item")
    {
    $item["Name"] = "[Name]_[ID]"
    $item.update()
    }
    }




    $spListItem.Update()

    Tuesday, January 17, 2017 10:18 PM

Answers

  • Hi,

    We can use the following Script to achieve it.

    # Get SharePoint list
    $web = Get-SPWeb "http://sp2013/sites/team"
    $list = $web.Lists["Test Library"]
    
    #Get all items in this list and save them to a variable
    $items = $list.items
     
    #Go through all items
    foreach($item in $items)
    {			
    	$item["BaseName"] = $item["Name"]+"_"+$item["ID"]
    	
    	#Update the item
    	$item.Update()		
    }

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by MonJohn Thursday, January 19, 2017 2:19 PM
    Thursday, January 19, 2017 3:19 AM
    Moderator

All replies

  • Hi,

    Here you go

    http://stackoverflow.com/questions/23408573/concatenate-a-column-in-a-csv-file

    https://levalencia.wordpress.com/2012/04/16/add-columns-to-existing-lists-via-powershell/


    Please remember to click Mark as Answer on the answer if it helps you

    Tuesday, January 17, 2017 10:58 PM
  • Hi,

    We can use the following Script to achieve it.

    # Get SharePoint list
    $web = Get-SPWeb "http://sp2013/sites/team"
    $list = $web.Lists["Test Library"]
    
    #Get all items in this list and save them to a variable
    $items = $list.items
     
    #Go through all items
    foreach($item in $items)
    {			
    	$item["BaseName"] = $item["Name"]+"_"+$item["ID"]
    	
    	#Update the item
    	$item.Update()		
    }

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by MonJohn Thursday, January 19, 2017 2:19 PM
    Thursday, January 19, 2017 3:19 AM
    Moderator
  • Awesome! Thank you Dennis! Perfect!
    Thursday, January 19, 2017 2:19 PM