-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathImport-PPSPWeb.ps1
108 lines (80 loc) · 2.92 KB
/
Import-PPSPWeb.ps1
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<#
$Metadata = @{
Title = "Import SharePoint Website"
Filename = "Import-PPSPWeb.ps1"
Description = ""
Tags = "powershell, sharepoint, function, import"
Project = ""
Author = "Janik von Rotz"
AuthorContact = "http://janikvonrotz.ch"
CreateDate = "2013-07-04"
LastEditDate = "2013-08-05"
Version = "1.0.0"
License = @'
This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/3.0/ or
send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
'@
}
#>
function Import-PPSPWeb{
<#
.SYNOPSIS
Import a SharePoint website.
.DESCRIPTION
Imort a SharePoint website into an existing website or a new one (requires Template parameter).
.PARAMETER Url
Url of the SharePoint website to overwrite or create.
.PARAMETER Path
Path to the backup file.
.PARAMETER Tempalte
SharePoint website template, default is "STS#0".
.PARAMETER NoFileCompression
Provide this parameter if the compressed website is oversized.
.EXAMPLE
PS C:\> Import-PPSPWeb -Url http://sharepoint.vbl.ch/Projekte/SitePages/Homepage.aspx -Path C:\Backup\SharePoint Superuser#2013-07-04 11-09-47.bak -Template "STS#1"
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[String]
$Url,
[Parameter(Mandatory=$true)]
[String]
$Path,
[Parameter(Mandatory=$false)]
[String]
$Template = "STS#0",
[Switch]
$NoFileCompression
)
#--------------------------------------------------#
# modules
#--------------------------------------------------#
if(-not (Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue)){Add-PSSnapin "Microsoft.SharePoint.PowerShell"}
#--------------------------------------------------#
# main
#--------------------------------------------------#
# extract spweb url
$SPUrl = $(Get-SPUrl $Url).Url
# get spweb object
$SPWeb = Get-SPWeb -Identity $SPUrl -ErrorAction SilentlyContinue
# if destination exists
if($SPWeb){
Import-SPWeb $SPWeb -Path $Path -UpdateVersions Overwrite -Force -IncludeUserSecurity -NoFileCompression:$NoFileCompression -NoLogFile -Confirm
# if destination not exists
}else{
# create a new site
New-SPWeb -Url $SPUrl -Template (Get-SPWebTemplate $Template)
# get new spweb object
$SPWeb = Get-SPWeb -Identity $SPUrl
# delete list items on new site
$spweb.Lists | %{
$_.AllowDeletion = $true
$_.Update()
$_.delete()
}
Import-SPWeb $SPWeb -Path $Path -UpdateVersions Overwrite -Force -IncludeUserSecurity -NoFileCompression:$NoFileCompression -NoLogFile -Confirm
}
Write-Host "Finished" -ForegroundColor Green
}