PowerShell change copied site collection's page RRS feed

  • Question

  • Hi,

    I've got a powershell script that does a Copy-SPSite from a template site collection I've made. After the creation of this site I want to change the title and some webparts on the new site collection's default page, but when I do this with the following powershell script: (the requests are a list with the title of the page, the url and a status to keep track what parts of the powershell script already ran)

    $Requests | foreach {
        $item = $_
        $url = $item["SiteUrl"].Split(',')[0]
        #Get reference to the SPSite object
        $SPsite = Get-SPSite $url
        #$web.TitleResource.SetValueForUICulture($web.UICulture, "TD")
        #$web.DescriptionResource.SetValueForUICulture($web.UiCulture, "Technische dienst")
        #$web.CreateDefaultAssociatedGroups("","", "TD")
        #Iterate through all sub sites and root site  
        foreach($SPWeb in $SPsite.AllWebs){
            #Get reference to the landing page. Since it is a publishing site so default.aspx is the landing page  
            $page = $SPWeb.GetFile($SPWebDefaultStartpagina)
            #Checkout the page  
            #Set page title
            #$page.Title = $item["Title"]
                "TeamsiteAanvraag" { 
                    #Get reference to the webpartmanager class  
                    $webpartmanager = $SPWeb.GetLimitedWebPartManager($SPWebDefaultStartpagina,   
                    $webpartmanager.WebParts | foreach{
                        $wp = $_
                                $wp.iPortalCategoryID = $item["DocumentCategoryId"];
                "ProjectenAanvraag" { $ItemType = "p" }
                "WerkgroepAanvraag" { $ItemType = "wg" }
            $page.CheckIn("Webpart updates")  
            $page.Publish("Webpart updates")  
            #Update the SPWeb object  
            #Dispose SPWeb object  
        SetItemStatus -item $item -text "Klaar"

    I get the error when I visit the default page: 

    Deze pagina gebruikt geen geldige pagina-indeling. Los het probleem op door de pagina-instellingen te bewerken en een geldige pagina-indeling te selecteren.

    In English something like: "This page uses an invalid page layout. Solve the problem by editing the page settings and selecting a valid page layout."

    However, if I visit the page after copying (and changing other things, except the script above) and than run the script above to change the page, it works perfectly. Sadly, this isn't automated because it requires a person to visit this page after copying the site collection.

    Can I automate this process?

    Thanks in advance,


    Monday, January 4, 2016 3:53 PM