0

Related question: Is "AllowUnsafeUpdates" available in SharePoint Online?

Since AllowUnsafeUpdates is not available via CSOM, i am trying to update this info in some manner.

I try this but no success

$adminUrl = "https://cutomer-admin.sharepoint.com"
$userName = "[email protected]"
$SPOSite ="https://customer.sharepoint.com/sites/SPSite1/"
$DefaultEmailAddress = "[email protected]"

Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.Online.SharePoint.Client.Tenant.dll"

$creds = Get-Credential -Credential $userName
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $creds
$SPOCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials -ArgumentList ($creds.Username, $creds.Password)

$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SPOSite)
$Ctx.Credentials = $SPOcredentials
$Web = $Ctx.Web
$SPODefaultEmailAddress = $web.EnsureUser($DefaultEmailAddress)
$Ctx.ExecuteQuery()
$Web.Author = $SPODefaultEmailAddress
$Web["Author"] = $SPODefaultEmailAddress
$Web.Update()
$Ctx.ExecuteQuery()

Does anyone know if this is possible?

1 Answer 1

0

In the above code, you are updating the SharePoint online web property,and here I think after web object client context load and executequery is missing.

You can little modify your code :

$Web = $Ctx.Web

$clientContext.Load(Web) $clientContext.ExecuteQuery()

  $SPODefaultEmailAddress = $web.EnsureUser($DefaultEmailAddress) $Ctx.ExecuteQuery()

  $Web.Author = $SPODefaultEmailAddress

  $Web.Update() 
 $Ctx.ExecuteQuery()

I think we can do this one using PnP PowerShell command as well.

You can try the below command :

  Connect-PnPOnline -Url https://ktskumar.sharepoint.com/mywork -Credentials (Get-Credential)
Set-PnPWeb -Title "My Work"

Note - in the above web title is being updated, you can change it to author.

https://www.ktskumar.com/2017/07/update-sharepoint-web-title-using-pnp-powershell/

Update :

  • Set-PnPWeb does not have author property.

  • In SharePoint server side dll, author property has both get and set but client side dll has only get property. So, we cannot change this property value in SharePoint online.

3

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.