0

We have a list with a column name category. Now we are removing a category value lets say CTGRY. So how can we update the category value to NEWCTGRY of all the items currently having category CTGRY.

We cannot do it manually as we have thousands of items in the list.

1

You can use the following PowerShell script to update your category column value.

cls
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
    Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

$sourceWebURL = "<Site URL>"
$sourceListName = "<Library Name>"

$spSourceWeb = Get-SPWeb $sourceWebURL
$spSourceList = $spSourceWeb.Lists[$sourceListName]
$spSourceItems = $spSourceList.Items | where {$_['Category'] -eq "CTGRY"}

$spSourceItems | ForEach-Object {
    $_['Category'] = "NEWCTGRY"
    $_.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.