locked
Exporting and Importing a site including nintex RRS feed

  • Question

  • Dear all,

    I am normally not the developer, but the technical farm consultant for SharePoint farms.  Recently, one of the developers who are no longer available wrote a script to export and import site collections that also include nintex workflows.  By the "ExportSite" function, I am stuck as it does not run this function.  When it goes to run the rest, it generates an error that the filename doesn't exist.  Can someone help me with the "ExportSite" function?  See code:

    #Add sharepoint pssnapin if it doesnt exist:
    if ( (Get-PSSnapin -Name microsoft.sharepoint.powershell -EA "SilentlyContinue") -eq $null )
    {
        Add-PsSnapin microsoft.sharepoint.powershell
    }


    function ExportSite{
        $filepath = $Title -replace '[\W]', ''
        write-host "Preparing all Nintex workflows for export..." -ForegroundColor Green
        $SourceSite = Get-SPSite -Identity $URL_Source
        $webs = Get-SPWeb -Site $SourceSite -Limit All
        foreach($web in $webs){
            $SourcewebURL = $web.url
            Write-Host "Preparing Nintex workflows on site $SourcewebURL" -ForegroundColor yellow
            NWAdmin -o preparesiteforexport -SiteUrl $SourcewebURL
        }
        Write-Host "Exporting new site $title..." -ForegroundColor Green
        Export-SPWeb -Identity $URL_Source -Path $ExportLocation\$filepath -IncludeUserSecurity -IncludeVersions All
        Write-Host "Export of site $title finished. The export file are on location $ExportLocation" -ForegroundColor Green
    }

    function ImportSite{
        $filepath = $Title -replace '[\W]', ''
        Write-Host "Creating new site $title..." -ForegroundColor Green
        New-SPSite -Url $URL_Target -OwnerAlias $OwnerAlias
        Write-Host "Importing new site $title..." -ForegroundColor Green
        Import-SPWeb -Identity $URL_Target -Path $ExportLocation\$filepath.cmp -ActivateSolutions -IncludeUserCustomAction All -IncludeUserSecurity -UpdateVersions Overwrite
        $Target_Site = Get-SPSite -Identity $URL_Target
        Write-Host "Restoring all Nintex workflows on all webs..." -ForegroundColor Green
        $webs = Get-SPWeb -Site $TargetSite -Limit All
        foreach($web in $webs){
            $TargetwebURL = $web.url
            Write-Host "Restoring Nintex workflows on site $TargetwebURL" -ForegroundColor yellow
            NWAdmin.exe -o FixSiteAfterImport -siteUrl $TargetwebURL
        }
        Write-Host "Site $title is now available on $URL_Target" -ForegroundColor Green
    }


    $title = "Sitecollectionname"
    $URL_Source = "http://sitecollection"
    $URL_Target = "http://sitecollection2"
    $ExportLocation = "<Drive>:\export"
    $OwnerAlias = "DOMAIN\user"

    #ExportSite
    ImportSite

    Thank you in advance,

    Blue

    • Moved by Bill_Stewart Friday, March 15, 2019 4:58 PM This is not "fix/debug/rewrite my script for me" forum
    Wednesday, January 2, 2019 1:02 PM

All replies

  • Sorry but this is not a free consulting forum or a free script fixing forum.  I recommend that you contact a trained tech who knows SharePoint and scripting to help you resolve this issue.

    See: This Forum is for Scripting Questions Rather than script requests <o:p></o:p>



    \_(ツ)_/

    Wednesday, January 2, 2019 1:12 PM
  • Hmmm...  Ok.  Well, maybe I should apologize and rephrase my "question" as I am not looking for any consulting.  I am looking for help, assistance and/or an answer to one of the lines in the particular function.  If I were looking for consulting, I would have asked a consultant :-P. What I would have appreciated is at least, in your answer, maybe a site that could help me with coding the specific problem area I am experiencing in the code.  I am looking to understand, learn an apply...

    Anyway, "my question" has to do with the line in the following code-----$filepath = $Title -replace '[\W]', ''----.  I tried to look up how to use "-replace" and what follows the option "[\W], ''. 

    The issue is this part of the script doesn't seem to run as it is supposed to create a file. 

    THEREFORE, my question is can anyone help me with either 1. how to find information (article/blog or that of the like) on how to specifically use -replace when replacing the variable to a text; or 2. help with how the syntax should go.

    function ExportSite{
        $filepath = $Title -replace '[\W]', ''
        write-host "Preparing all Nintex workflows for export..." -ForegroundColor Green
        $SourceSite = Get-SPSite -Identity $URL_Source
        $webs = Get-SPWeb -Site $SourceSite -Limit All
        foreach($web in $webs){
            $SourcewebURL = $web.url
            Write-Host "Preparing Nintex workflows on site $SourcewebURL" -ForegroundColor yellow
            NWAdmin -o preparesiteforexport -SiteUrl $SourcewebURL
        }
        Write-Host "Exporting new site $title..." -ForegroundColor Green
        Export-SPWeb -Identity $URL_Source -Path $ExportLocation\$filepath -IncludeUserSecurity -IncludeVersions All
        Write-Host "Export of site $title finished. The export file are on location $ExportLocation" -ForegroundColor Green
    }

    Once again, thank you for any assistance

    Thursday, January 3, 2019 5:52 AM
  • Thursday, January 3, 2019 6:03 AM
  • Thank you.  I finally found some information regarding regex and how the \W works.  That further helped me understand what was going on and I was able to fix the issue myself.  The issue had to do with global variables as well as some other variable calling in some lines.

    Thank you also for the information you gave for referencing.  I will specifically look at the reference relating to posting technical questions.

    Happy New year! PLH

    Thursday, January 3, 2019 7:54 AM
  • I should note that in the code you posted, the line that invokes the ExportSite function is commented out, so it does not run. The "#" character makes what follows on the line a comment.

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Thursday, January 3, 2019 1:24 PM