Articles about European Sharepoint Hosting Service
SharePoint 2013 Hosting UK – HostForLIFE.eu :: Find Default Page And Approve It Using Powershell In SPO
Basically in SPO, default.aspx are discontinued however while migration default pages also get migrated. Here this piece of code finding default pages as it may set up Homepage of sites.

Here, we are finding those default pages across site and subsites and approving it along with the particular user who created or modified.

Here, we are finding those default pages across site and subsites and approving it along with the particular user who created or modified.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
#Passing inputs through CSV file # Pass Site URL and Library Name as Inputs. Param( [Parameter(Mandatory = $true)] [string] $Csv) # Pass your DLL 's Add - Type - Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll" Add - Type - Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" Add - Type - Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Publishing.dll" Import - Module Microsoft.Online.SharePoint.PowerShell # Not required for on premise site - Start $userId = "xxxx@msdcloud.onmicrosoft.com" $pwd = Read - Host - Prompt "Enter password" - AsSecureString $creds = New - Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userId, $pwd) $root = Import - Csv $Csv foreach($record in $root) { $TargetSite = $record.SharePointUrl $LibraryName = $record.LibraryName $ctx = New - Object Microsoft.SharePoint.Client.ClientContext($TargetSite) # Not required for on premise site - Start $ctx.credentials = $creds # Iterating across subsites and finding default pages. $web = $ctx.Web $ctx.Load($web.Webs) $ctx.ExecuteQuery() if ($web.Webs.Count - gt 0) { foreach($AllWeb in $web.Webs) { try {# Get all files from the Library $List = $AllWeb.Lists.GetByTitle($LibraryName) $q = New - Object Microsoft.SharePoint.Client.CamlQuery $q.ViewXml = "<View Scope='RecursiveAll' />" $Items = $List.GetItems($q) $ctx.Load($Items) $ctx.ExecuteQuery() $FileName = "default.aspx" Foreach($Item in $Items) { $File = $Item["FileRef"].Substring($Item["FileRef"].LastIndexOf("/") + 1) if ($File - eq $FileName) { if ($Item["_ModerationStatus"] - eq "2" - and($Item["Editor"].LookupValue - eq("xxxUserName") - or $Item["Editor"].LookupValue - eq("xxxUserName"))) { $Item["_ModerationStatus"] = "0" $Item.Update() $ctx.ExecuteQuery() write - host "done" } } } } catch { $_ | Out - File errors.txt - Append } } } if ($web.Webs.Count - eq 0) { try { #Get all files from the Library $List = $AllWeb.Lists.GetByTitle($LibraryName) $q = New - Object Microsoft.SharePoint.Client.CamlQuery $q.ViewXml = "<View Scope='RecursiveAll' />" $Items = $List.GetItems($q) $ctx.Load($Items) $ctx.ExecuteQuery() $FileName = "default.aspx" Foreach($Item in $Items) { $File = $Item["FileRef"].Substring($Item["FileRef"].LastIndexOf("/") + 1) if ($File - eq $FileName) { if ($Item["_ModerationStatus"] - eq "2" - and($Item["Editor"].LookupValue - eq("xxxUserName") - or $Item["Editor"].LookupValue - eq("xxxUserName"))) { $Item["_ModerationStatus"] = "0" $Item.Update() $ctx.ExecuteQuery() write - host "done" } } } } catch { $_ | Out - File errors.txt - Append } } } |
Moderation Status is a 4-byte integer indicating the moderation approval status of a list item.
Configurations can require moderation approval to publish a list item or allow automatic approval. A published list item MUST have a Moderation Status of 0. The following are all possible valid values for Moderation Status.
Print article | This entry was posted by Peter on August 21, 2018 at 7:58 am, and is filed under European SharePoint 2013 Hosting. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |