I needed to export and import all web in site collection to a new Site collection, which was based on a different language template.

In order to automate the process I, of course, used PowerShell. I was trying to figure out, what would be the best way to name the exported webs and found this article on TechNet Forums:

http://social.technet.microsoft.com/Forums/en-US/sharepoint2010setup/thread/65e5e221-4d1f-428c-8803-f46f98171651/

 

This lead me to write script for exporting webs to be:

 

#Get all webs in site collection

$webs=Get-SPSite http://razvoj/sites/ang |Get-SPWeb -limit all

#Export-Spweb

foreach($web in $webs){$filename=$web.url.replace("http://","").replace("-","--").replace("/","-")+".cmp"; Export-SPWeb $web -Path c:\export\$filename -IncludeVersions all -IncludeUserSecurity -Verbose}

 

When you create new Site collection on a team site for example, there are some list and libraries which I found is best to delete them to avoid errors when importing webs.

#Delete lists and libraries on a new site collection to avoid errors when importing
for($i=0;$i -lt $seznami.Count;$i++){$seznami.delete($seznami[$i].id)}

The next step is to get all files in a c:\Export folder which has the extension of ».cmp«. For this I wrote a script:

#Get all files in folder with .cmp extension
$list=Get-ChildItem c:\export | where {$_.extension -eq ".cmp"}

And the final step is to import all webs to a new site collection:

#Import all files and use file name as reference to where web should be created
foreach($listitem in $list){$importweb=$listitem.name.replace("razvoj-","http://razvoj/").replace("-","/").replace("ang","slo").replace(".cmp",""); import-spweb $importweb -UpdateVersions overwrite -Path c:\export\$listitem -Force -IncludeUserSecurity -Verbose}

Hope this helps.

Robi Vončina