powershell Powershell脚本复制网站然后多次使用它,有点像模板。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell Powershell脚本复制网站然后多次使用它,有点像模板。相关的知识,希望对你有一定的参考价值。

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction Stop

try{
$web = Get-SPWeb http://portal.opwftg.com/sites/OPWSS/Teams/Safety/SiteTemplate/IncidentReports
write-host “Web Template:” $web.WebTemplate ” | Web Template ID:” $web.WebTemplateId

$template = $web.WebTemplate

$TargetWebURL1 = "http://portal.opwftg.com/sites/OPWSS/Teams/Safety/FCC/IncidentReports"
$TargetWebURL2 = "http://portal.opwftg.com/sites/OPWSS/Teams/Safety/FCS/IncidentReports"
$TargetWebURL3 = "http://portal.opwftg.com/sites/OPWSS/Teams/Safety/FMS/IncidentReports"
$TargetWebURL4 = "http://portal.opwftg.com/sites/OPWSS/Teams/Safety/KNP/IncidentReports"
$TargetWebURL5 = "http://portal.opwftg.com/sites/OPWSS/Teams/Safety/MID/IncidentReports"
$TargetWebURL6 = "http://portal.opwftg.com/sites/OPWSS/Teams/Safety/PDQ/IncidentReports"

$SiteName = "Incident Reports"

$newWeb = New-SPWeb -Url $TargetWebURL1 -Name $SiteName
$newWeb.ApplyWebTemplate($template)
write-host 'Created 1'

$newWeb = New-SPWeb -Url $TargetWebURL2 -Name $SiteName
$newWeb.ApplyWebTemplate($template)
write-host 'Created 2'

$newWeb = New-SPWeb -Url $TargetWebURL3 -Name $SiteName
$newWeb.ApplyWebTemplate($template)
write-host 'Created 3'

$newWeb = New-SPWeb -Url $TargetWebURL4 -Name $SiteName
$newWeb.ApplyWebTemplate($template)
write-host 'Created 4'

$newWeb = New-SPWeb -Url $TargetWebURL5 -Name $SiteName
$newWeb.ApplyWebTemplate($template)
write-host 'Created 5'

$newWeb = New-SPWeb -Url $TargetWebURL6 -Name $SiteName
$newWeb.ApplyWebTemplate($template)
write-host 'Created 6'

$SourceWebURL = "http://portal.opwftg.com/sites/OPWSS/Teams/Safety/SiteTemplate/IncidentReports"
$BackupPath = "E:\temp\TempSave"

Export-SPweb $SourceWebURL -IncludeUserSecurity -IncludeVersions All -path ($BackupPath + ".cmp") -nologfile -Force
write-host 'Done Backup'

import-spweb $TargetWebURL1 -IncludeUserSecurity -path ($BackupPath + ".cmp") -nologfile -UpdateVersions Overwrite
write-host 'Imported 1'

import-spweb $TargetWebURL2 -IncludeUserSecurity -path ($BackupPath + ".cmp") -nologfile -UpdateVersions Overwrite
write-host 'Imported 2'

import-spweb $TargetWebURL3 -IncludeUserSecurity -path ($BackupPath + ".cmp") -nologfile -UpdateVersions Overwrite
write-host 'Imported 3'

import-spweb $TargetWebURL4 -IncludeUserSecurity -path ($BackupPath + ".cmp") -nologfile -UpdateVersions Overwrite
write-host 'Imported 4'

import-spweb $TargetWebURL4 -IncludeUserSecurity -path ($BackupPath + ".cmp") -nologfile -UpdateVersions Overwrite
write-host 'Imported 5'

import-spweb $TargetWebURL4 -IncludeUserSecurity -path ($BackupPath + ".cmp") -nologfile -UpdateVersions Overwrite
write-host 'Imported 6'
}
catch{
"Something strange occurred: $_"
}
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction Stop

try{
$web = Get-SPWeb http://portal.opwftg.com/sites/OPWSS/Teams/Safety/SiteTemplate/IncidentReports
write-host “Web Template:” $web.WebTemplate ” | Web Template ID:” $web.WebTemplateId

$template = $web.WebTemplate

$TargetWebURL1 = "http://portal.opwftg.com/sites/OPWSS/Teams/Safety/InternationalSafety/Brazil2/Incident Reports"
$TargetWebURL2 = "http://portal.opwftg.com/sites/OPWSS/Teams/Safety/InternationalSafety/CzechRepublic2/Incident Reports"
$TargetWebURL3 = "http://portal.opwftg.com/sites/OPWSS/Teams/Safety/InternationalSafety/Fibrelite2/Incident Reports"
$TargetWebURL3 = "http://portal.opwftg.com/sites/OPWSS/Teams/Safety/InternationalSafety/JUMP2/Incident Reports"
$TargetWebURL4 = "http://portal.opwftg.com/sites/OPWSS/Teams/Safety/InternationalSafety/Suzhuo2/Incident Reports"

$newWeb = New-SPWeb -Url $TargetWebURL1 -Name 'Incident Reports'
$newWeb.ApplyWebTemplate($template)
write-host 'Created 1'

$newWeb = New-SPWeb -Url $TargetWebURL2 -Name 'Incident Reports'
$newWeb.ApplyWebTemplate($template)
write-host 'Created 2'

$newWeb = New-SPWeb -Url $TargetWebURL3 -Name 'Incident Reports'
$newWeb.ApplyWebTemplate($template)
write-host 'Created 3'

$newWeb = New-SPWeb -Url $TargetWebURL4 -Name 'Incident Reports'
$newWeb.ApplyWebTemplate($template)
write-host 'Created 4'

$SourceWebURL = "http://portal.opwftg.com/sites/OPWSS/Teams/Safety/SiteTemplate/IncidentReports"
$BackupPath = "E:\temp\TempSave"

Export-SPweb $SourceWebURL -IncludeUserSecurity -IncludeVersions All -path ($BackupPath + ".cmp") -nologfile -Force

import-spweb $TargetWebURL1 -IncludeUserSecurity -path ($BackupPath + ".cmp") -nologfile -UpdateVersions Overwrite
write-host 'Imported 1'

import-spweb $TargetWebURL2 -IncludeUserSecurity -path ($BackupPath + ".cmp") -nologfile -UpdateVersions Overwrite
write-host 'Imported 2'

import-spweb $TargetWebURL3 -IncludeUserSecurity -path ($BackupPath + ".cmp") -nologfile -UpdateVersions Overwrite
write-host 'Imported 3'

import-spweb $TargetWebURL4 -IncludeUserSecurity -path ($BackupPath + ".cmp") -nologfile -UpdateVersions Overwrite
write-host 'Imported 4'
}
catch{
"Something strange occurred: $_"
}

以上是关于powershell Powershell脚本复制网站然后多次使用它,有点像模板。的主要内容,如果未能解决你的问题,请参考以下文章

powershell Quick Powershell脚本用于复制文件并使用文件类型过滤保留文件夹结构

powershell Quick Powershell脚本用于复制文件并使用文件类型过滤保留文件夹结构

如何在 PowerShell 复制脚本中正确过滤多个字符串

一键帮你复制多个文件到多个机器——PowerShell小脚本(内附PS远程执行命令问题解析)

如何编写Powershell脚本以提取.iso文件并通过创建文件夹将其复制到文件夹中

使用 PowerShell 复制没有文件的文件夹、没有文件夹的文件或所有内容