0

we have a sharepoint online classic team site. and inside the classic team site, we have a custom list titled "Project Management" which have a custom drop down field named "ProjectStatus", which have 5 values such as; "Active", "In Progress", etc...

now i want to remap the "Project Management" list's items "ProjectStatus", as follow:-

  1. if "ProjectStatus" = "Active" to map it as "Live".

  2. if "ProjectStatus" = "In Progress" to map it as "not completed yet".

so can i run a PnP script to loop through all the list's items and update their statuses according to the above mapping? also not to affect the list items' modified date + modified by?

Thanks

2

First, modify the column "ProjectStatus" values in list settings, change "Active" to "Live" and change "In Progress" to "not completed yet".

Then run the PnP PowerShell below.

Connect-PnPOnline -Url https://tenant.sharepoint.com/sites/lz -Credentials (Get-Credential)
$listName="Project Management"
$listItems= Get-PnPListItem -List $listName

foreach ($item in $listItems)
{
    if($item["ProjectStatus"] -eq "Active"){
        Set-PnPListItem -List $listName -Identity $item.ID -Values @{"ProjectStatus" = "Live"} -SystemUpdate
    }
    if($item["ProjectStatus"] -eq "In Progress"){
        Set-PnPListItem -List $listName -Identity $item.ID -Values @{"ProjectStatus" = "not completed yet"} -SystemUpdate
    }
}
3

Yes, you can use Get-PnPListItem with CAML query to fetch the based on your conditions and then update them using Set-PnPListItem and passing the SystemUpdate parameter which wont change the modified and modified by fields.

You can modify from below sample code for Active projects :

$listItems= Get-PnPListItem -List "Project Management" -Query "<View><Query><Where><Eq><FieldRef Name='ProjectStatus'/><Value Type='Text'>Active</Value></Eq></Where></Query></View>"

foreach ($item in $items)
{

    Set-PnPListItem -List $list -Identity $item.ID -Values @{"ProjectStatus" = "Live"} -SystemUpdate

}

You can repeat the same for Not completed projects by changing the caml query again running the code again.

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.