0

I have migrated an old enterprise wiki site collection 2013 to SharePoint online. I did not create the source site collection, and i found that the wiki pages are associated with the built-in Enterprise Wiki Page content type and the built-in EnterpriseWiki.aspx page layout. And those 2 built components were customized by adding new site columns to them. As i know that modifying the built-in components (Content type and the Page layout) are not recommended, because the modification might get overridden by Microsoft if they apply an update. so i create a new content type which mimic the built-in one and i create a new layout which mimic the the built-in one.

But i am not sure if i can write a PnP script to update the enterprise wiki pages's Content type and Page layout without affecting the wiki pages' metadata (mainly the modified date and modified by)?

0
+50

Per my knowledge, if we change content type or page layout, the modified date and modified by will changed regardless of using PnP script or other ways.

|improve this answer|||||
  • ok i see, i do not want all my modified date and modifiedBy to get updated.. so let me change my question, is there a real risk if i keep things as-is? is there a real risk of having the modification get overridden ? – SharePoint TestDev Jan 3 at 9:35
  • There is really no "risk" to performing this kind of bulk update and allowing the modified fields get updated. Many business users don't like seeing their admin's username as the lastmodifiedBy, but there is no technical reason no to just do it. It may be more palatable to your business users if you can have a dedicated user account named something like 'Administrative Updater' instead of a real person's name, and execute the script under those credentials. – willman Jan 7 at 21:54
1

If you use Set-PnPListItem to change the Content Type and/or Page Layout, as long as you use the -SystemUpdate switch parameter, it will NOT update the Modified and Editor values, for example:

Set-PNPListItem -List $yourlist -Identity $itemId2Update -Values @{"ContentTypeId"=$ct.StringId} -SystemUpdate;

That is probably the simplest and recommended approach, but alternatively, if you have "full control" permissions on the list, you can use Set-PnPListItem to change the Modified and related field value After you have made some change that caused an update. For example:

Set-PnPListItem -List $yourlist -Identity $itemId2Update -Values @{"Modified"=$NewModifiedDate;"Created"=$NewCreateDate;"Author"="some@yourtenanturl.com";"Editor"="someoneelse@yourtenanturl.com";}

Some caveats to this, first, do NOT use the -SystemUpdate parameter with this second technique, as that flag forces it to NOT update the Modified and Editor fields. Also, it seems to only work if you set all four of those values at the same time. If you want to keep the Created and Author values the same, and just change the Modified and Editor values, then set Created and Author to copies of their existing values -- if you simply leave them out, the whole thing doesn't work -- no error message, it just doesn't take affect. You will also want to save it using the UpdateOverwriteVersion method, otherwise, although the newer version will take your new values, the old version will still have your previous values.

|improve this answer|||||
  • now i wrote the following to change the Page Layout Set-PNPListItem -List "Customer Service KB" -Identity "3024" -Values @{"PublishingPageLayout"="https://***.sharepoint.com/sites/CustomerServiceKB/_catalogs/masterpage/EnterpriseWiki.aspx"} -SystemUpdate;, where the Modified date did not get updated, but the ModifiedBy was change! so the -SystemUpdate will change the Modified By... – SharePoint TestDev Jan 6 at 16:49
  • It's always confusing when SharePoint is expecting a full absolute URL, a server-relative url, a site-relative url, or simple page name. I would suggest that you get a reference to your desired page layout ListItem using get-pnplistitem, then in your Set-PNPListItem, set "PublishingPageLayout" = $yourpagelayoutitem["FileRef"] – willman Jan 6 at 16:50
  • now i wrote the following to change the Page Layout Set-PNPListItem -List "Customer Service KB" -Identity "3024" -Values @{"PublishingPageLayout"="https://***.sharepoint.com/sites/CustomerServiceKB/_catalogs/masterpage/EnterpriseWiki.aspx"} -SystemUpdate; where the Modified date did not get updated, but the ModifiedBy was change! so the -SystemUpdate will change the Modified By – SharePoint TestDev Jan 6 at 17:53
  • The -SystemUpdate is not supposed to update either of those values, but it does not surprise me that there is probably some quirks to that one. Have you tried the second technique of using grabbing the original Modified By value and using Set-pnpListItem to change the Modified back to what it was? – willman Jan 6 at 21:27
  • did not work either... – SharePoint TestDev Jan 7 at 2:32

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.