if((
Get-PSSnapin
|
Where
{$_.Name
-eq
"Microsoft.SharePoint.PowerShell"
})
-eq
$null
)
{
Add-PSSnapin
Microsoft.SharePoint.PowerShell;
}
$ErrorActionPreference
=
"Stop"
$outputPath
=
"D:\Test-Backup\Results.csv"
try
{
Add-Content
-Path
$outputPath
-Value
"Site Name, Type,Message,Source Site Path,Source Site,DateTime,New Content DB,New Site Address"
$rootSite
=
New-Object
Microsoft.SharePoint.SPSite(
$siteUrl
)
$spWebApp
=
$rootSite
.WebApplication
$destinationRootSite
=
New-Object
Microsoft.SharePoint.SPSite(
$destinationSiteUrl
)
$destinationWebApp
=
$destinationRootSite
.WebApplication
$count
= 0
$sitesToSkip
= @(
"/erooms/BAS"
,
"/erooms/CorporateFinance"
,
"/erooms/RASdebtorsportal"
)
$siteCount
= 0
$ContentDB
=
"SP10PROD_Content_ERooms1"
foreach
(
$site
in
$spWebApp
.Sites)
{
$path
= (
$site
.URL
-split
'.com/erooms/'
)[1]
if(
$path
-NotLike
""
)
{
$DestSites
=
$destinationWebApp
.Sites |
where
{$_.URL
-Like
$(
"*/s/"
+
$path
)} |
measure-object
try
{
if(
$DestSites
.Count
-eq
0)
{
if(
$site
.ContentDatabase.Name
-eq
"MOSSp_Content_eRoomsarchive"
)
{
Write-Host
$(
"D:\\Test-Backup\" + $path + "
.bak")
Backup
-SPSite
-Identity
$site
.URL
-Path
$(
"D:\Test-Backup\" + $path + "
.bak")
-force
Add-Content
-Path
$outputPath
-Value
$(
$site
.Title +
",Success - Archive,Backup from Source Site Collection Successful,"
+
$site
.URL +
","
+
$path
+
","
+ $(
Get-Date
))
Restore
-SPSite
-Identity
$(
"http://myteam.au.mywestfield.com/s/"
+
$path
)
-Path
$(
"D:\\Test-Backup\" + $path + "
.bak
") -DatabaseName "
SP10PROD_Content_ERooms_Archive"
-Confirm
:
$false
-Force
Add-Content
-Path
$outputPath
-Value
$(
$site
.Title +
",Success - Archive,Backup restored on New Web Application! Successful,"
+
$site
.URL +
","
+
$path
+
","
+ $(
Get-Date
) +
",SP10PROD_Content_ERooms_Archive"
+
",http://myteam.au.mywestfield.com/s/"
+
$path
)
Remove-Item
(
"D:\\Test-Backup\\"
+
$path
+
".bak"
)
Add-Content
-Path
$outputPath
-Value
$(
$site
.Title +
",Success - Archive,Backup File Removal Successful,"
+
$site
.URL +
","
+
$path
+
","
+ $(
Get-Date
))
}
else
{
if(
$sitesToSkip
-contains
$(
"/erooms/"
+
$path
))
{
Write-Host
$(
"Site Skipped!! "
+
$path
)
Add-Content
-Path
$outputPath
-Value
$(
$site
.Title +
",Skipped,Site is Skipped As per Instrcutions of Owner,"
+
$site
.URL +
","
+
$path
+
","
+ $(
Get-Date
))
}
else
{
Write-Host
$(
"D:\\Test-Backup\" + $path + "
.bak")
Backup
-SPSite
-Identity
$site
.URL
-Path
$(
"D:\Test-Backup\" + $path + "
.bak")
-force
Add-Content
-Path
$outputPath
-Value
$(
$site
.Title +
",Success,Backup from Source Site Collection Successful,"
+
$site
.URL +
","
+
$path
+
","
+ $(
Get-Date
))
if(
$siteCount
-lt
31)
{
$ContentDB
=
"SP10PROD_Content_ERooms1"
$siteCount
=
$sitecount
+ 1
}
elseif (
$siteCount
-gt
30
-and
$siteCount
-lt
61)
{
$ContentDB
=
"SP10PROD_Content_ERooms2"
$siteCount
=
$sitecount
+ 1
}
elseif(
$siteCount
-gt
60)
{
$ContentDB
=
"SP10PROD_Content_ERooms3"
$siteCount
=
$sitecount
+ 1
}
Add-Content
-Path
$outputPath
-Value
$(
$site
.Title +
",Success,Backup restored on New Web Application! Successful,"
+
$site
.URL +
","
+
$path
+
","
+ $(
Get-Date
) +
","
+
$ContentDB
+
",http://myteam.au.mywestfield.com/s/"
+
$path
)
Remove-Item
(
"D:\\Test-Backup\\"
+
$path
+
".bak"
)
Add-Content
-Path
$outputPath
-Value
$(
$site
.Title +
",Success,Backup File Removal Successful,"
+
$site
.URL +
","
+
$path
+
","
+ $(
Get-Date
))
}
}
}
else
{
Write-Host
$(
"Exists!! "
+
$Dest
.URL)
Add-Content
-Path
$outputPath
-Value
$(
$site
.Name +
",Already Exists,Site with same Path already exists on Destination Server,"
+
$site
.URL +
","
+
$path
+
","
+ $(
Get-Date
) +
",,http://myteam.au.mywestfield.com/s/"
+
$path
)
}
}
catch
{
Write-Host
$(
"Cannot Access Site Collection: "
+
$path
+
" ----- "
+
$error
[0])
Add-Content
-Path
$outputPath
-Value
$(
$site
.Title +
",Error,Site Collection Movement Unsuccessful -----"
+
$error
[0] +
","
+
$site
.URL +
","
+
$path
+
","
+ $(
Get-Date
))
}
}
$site
.Dispose()
}
}
catch
{
Write-Host
$(
"Cannot Access Site Collection: "
+
$path
+
" ---- "
+
$error
[0])
Add-Content
-Path
$outputPath
-Value
$(
$site
.Title +
",Error,Error in Script startup ----"
+
$error
[0] +
","
+
$site
.URL +
","
+
$path
+
","
+ $(
Get-Date
))
}