Struggeling with Microsoft.SharePoint.Client.Site.Classification - Update is only valid for a short time
Category
- [x] Question
- [ ] Typo
- [ ] Bug
- [ ] Additional article idea
Expected or Desired Behavior
Setting programmatically Microsoft.SharePoint.Client.Site.Classification to a value, that value gets persisted as long as it is not changed and displayed in modern experience site below the Site Title as shown in Vesa's PnP Short Video. https://www.youtube.com/watch?v=E-8Z2ggHcS0&list=PLR9nK3mnD-OXZbEvTEPxzIOMGXj_aZKJG
Observed Behavior
When I set the update, the value takes effect and is shown. But after a while, maybe forced by reopening the browser or what ever it disappears in the UI and a check via code assures that the value is empty. Looks like it's overwritten from 'somewhere'?
Steps to Reproduce
Configure your tenant like mentioned by Vesa in above's PnP Short video OR skip this step (doesn't matter for my result) Use PnP Powershell or CSOM (code / PS) to set the value to one you like (is a pre-configured entry from procedure above or not, doesn't matter) to update that setting: $site = $clientContext.Site $clientContext.Load($site) $clientContext.ExecuteQuery() $site.Classification = "Non-Confidential" $clientContext.ExecuteQuery()
OR
Connect-PnPOnline -Url $siteUrl -Credentials $credentials $site = Get-PnPSite Get-PnPProperty -ClientObject $site -Property "Classification" $site.Classification = "New Test" Execute-PnPQuery
I checked several options but did not find a solution. Am I missing something or is there a bug? Setting the value via UI indeed "lasts forever" but we have an automatic provisioning solution in place here ;-)
This is not a SP-Dev-Docs question. Could you ask this question in the https://github.com/SharePoint/PnP forum? Thanks.
Is not? Was directed here by @VesaJuvonen but will open another issue, no problem. Going on here https://github.com/SharePoint/PnP/issues/1705
@mmsharepoint - We're working on a definite answer for this. Clarifying few things to get it 100% accurate.
For the moment we established a workaround with the "old" Exchange Online cmdlets: $ExchangeOnlineSession = New-PSSession -ConfigurationName Microsoft.Exchange ... ... Set-UnifiedGroup ... That's working. (Although it takes a long time to get effect in case you have the site already open?) But I know this is not the future path and therefore I am curious and looking forward to your accurate answer on the correct guidance for setting the group classification programmatically @VesaJuvonen Thanks so much Markus
has there been any conclusion on this as it has been asked on the community as well but no advice given.
it has also been pointed out that although you can provision a Comms site with a classification, there is no GUI way to change the value. so a programmatic method would be helpful.
I have retested this myself and can confirm the behaviour as outlined above. Powershell code successfully changes the value. As soon as the site is opened from the browser the old value is pushed from somewhere and the change is overwritten. This is actually briefly visible in o365 as you can first see the altered value rendered then it changes in front of you back to the old value. bizarre.
Connect-PnPOnline -Url $siteUrl -Credentials $cred $site = Get-PnPSite Get-PnPProperty -ClientObject $site -Property Classification $site.Classification $site.Classification = "Test" Execute-PnPQuery
In the meantime I tested the new New-PnPSite command which got available recently. Unfortunately it seems not yet applicable to really provision Groups so far:
- A new teamsite gets created together with a Group
- The cmdlet provides a -Classification attribute
- Against the New-PnPUnifiedGroup it does not provide an attribute for Owners and Members
- Once the Group is created a Classification seems not to be set although the attribute was used
- Owners and Members seem not to be adjusted by using the Set-PnPUnifiedGroup cmdlet afterwards
So far I use a combination of New-PnPUnifiedGroup for creating a Group with additiona Owners and Members Set-UnifiedGroup from the "old" ExchangeOnline cmdlets for successfully setting the Group classification. Unfortunately the Exchange Online cmdlets are not very comfortable as you always have to import a PSSession within your script. I use an Azure runbook for provisionining and this is not very fast and produces lots of logging when running in verbose mode during testing
Let's see what the new API on which the brandnew New-PNPSite command is based will provide us in the near future.
a new video just released a few days ago "working with tenant properties" by vesa and waldek still advises that the setter will work although they suggest that the tenant group value takes priority and this takes some time for the update to get applied in a background operation. so they confirm that you would expect the value to be set, then change back , then change again to the desired setting once the background group gets synced. They say this also works for comms sites although they do not comment on how this relates to the group as the site does not have a group... The comments about this are rather muddy and difficult to follow.
having tested the CSOM updating as per the video, the experience does not correspond with the published video advice currently. It would be great if either Vesa or Waldek could comment on what is working at the moment. I have raised this as a bug as well now.
i have logged this as a bug on https://github.com/SharePoint/sp-dev-docs/issues/1031 communication sites are not a problem and the change persists in my tests so far.
But in the recent SIG call Paolo demonstrated the work and I totally understood the behavior: There he mentioned that for a Team site you cannot modify the siite's property but have to modify the Group. Only for communication sites this is working. Check out his demo: https://techcommunity.microsoft.com/t5/SharePoint-Developer/SharePoint-Patterns-amp-Practices-General-SP-Dev-SIG-recording/m-p/123822 (beginning 8:30) Fortunately there is one method now that do the right thing in both ways. Meanwhile I am waiting for adequate representation in PowerShell or will check out CSOM within PowerShell.
Just FYI: The new "SetSiteClassification" extension method is available in the PnPCore library now and seems working very well. Apart from that there are also cool new PnP cmdlets to enable the site classifications on tenant level in advance. Check it out. As I am still not satisfied with the classification setting in PnP PowerShell (Set-PnPUnifiedGroup does not provide, New-PnPSite seems not to work) I will give a CSOM driven appraoch with SetSiteClassification now a chance.
thanks Markus, I will have a try out with that and see if that wraps it up.
I also wrote a short blogpost on how it can be solved now https://mmsharepoint.wordpress.com/2017/11/13/set-the-site-classification-with-pnp-powershell-and-pnp-core-component-siteextension-method/ For me this approach worked successfully so far. We already provisioned dozens of Groups last 2 days ...
Seems like this issue is resolved... yes?
Oh yes, indeed it is. For some time I used above workaround but nowadays I use Set-PnPSite repsectively Set-PnPUnifiedGroup for this. Is there a good hint how I can easily track/see my opened issues here? Already forgot this one ;-)
Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues