0

I currently have the following script which works great for its intended use.

Here is the original post: Powershell script to update list column from another column Conditional

I have the need to update a date in a column if it is empty, the below script works fine for this however my requirements have now changed and the fields are now in separate lists within the site.

Here is the script:

#Add SharePoint PowerShell Snapin which adds SharePoint specific cmdlets
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue

#Variables that we are going to use for list editing
$listName = "Approvals"

#Get the SPWeb object and save it to a variable
$web = Get-SPWeb http://discoverydev09/

#Get the SPList object to retrieve the "Demo List"
$list = $web.Lists[$listName]


#Get all items in this list and save them to a variable
$items = $list.items

#Go through all items
foreach($item in $items)
{
    $user = $item["testupdatedate"]
    #Change the value of the "Title" column
    $testPublishedDate = $item["TestPublishedDate"]

    if(!$testPublishedDate)
    {
        $item["TestPublishedDate"] = $user
    }
    #Update the item
    $item.Update()

}

The field testupdatedate is now in a separate list called 'approvals2' which is in another location in the site.

I have tried many times assigning variables to both lists and list items without success.

Can anyone recommend the best way to achieve this?

Thanks in advance

4
  • List 'Approvals' have more than 5000 items and in a list 'approvals2' do you have only one item with testupdatedate field populated or many?
    – Marko Tica
    Sep 26, 2019 at 11:30
  • Hi Marko, There are a similar amount of items in the second list. with multiple other columns.
    – Adz127
    Sep 26, 2019 at 12:18
  • How these items are connected in that 2 lists? This field 'testupdatedate' is same for all items or per item? Can you update your question?
    – Marko Tica
    Sep 26, 2019 at 14:14
  • Can you post what you have tried? Sep 27, 2019 at 13:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.