Posts Tagged site collection

SharePoint Online – List of Sites & Webs

Scenario:

Need to create a PowerShell script that iterates through all SharePoint Online site collections and webs and generate info. regarding site collection size, last time site/web update and other.

Resolution:

Tweaked script by Jose Quinto @ https://blog.josequinto.com/2016/03/17/using-powershell-to-retrieve-all-sites-web-object-recursively-from-sharepoint-online/.

Output is two CSV files in temp folder on C drive root. One with the details and other with site collection on which account gets 401 error.

$Global:webinfo = @()

function AuthenticateUserProfile($siteUrl, $tenantAdmin, $secureAdminPassword)
{
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($tenantAdmin, $secureAdminPassword)
$ctx.Credentials = $credentials
return $ctx
}

function RecursiveWebs($ctx, $web){

foreach($w in $web.Webs)
{
$ctx.Load($w.Webs);
$ctx.ExecuteQuery();

$Properties = @{
Title = $w.Title
URL = $w.Url
NoOfSubsites = $w.Webs.Count
LastUserModifiedDate = $w.LastItemUserModifiedDate
LastItemModifiedDate = $w.LastItemModifiedDate
SiteCollection = ‘No’
SiteOwner = $w.Author.Title
}

$Global:webinfo += New-Object psobject -Property $properties

if ($w.Webs.Count -gt 0)
{
RecursiveWebs $ctx $w
}
}
}

$username = “adm@test.com”
$password = ConvertTo-SecureString “PASSWORD” -AsPlainText -Force
$O365Credential = New-Object System.Management.Automation.PsCredential($username, $password)

#SharePoint Online Admin site URL
Connect-SPOService -Url https://test-admin.sharepoint.com -Credential $O365Credential
$sites = Get-SPOSite -Limit All -Detailed

foreach ($site in $sites)
{
if(
$site.Url.Equals(“https://test.sharepoint.com/sites/new”) -or
$site.Url.Equals(“https://test.sharepoint.com/search”)
)
{
continue;
}

Write-Host $site.Url
try
{
$ctx = AuthenticateUserProfile $site.Url $username $password;
$web = $ctx.Web
$ctx.Load($web)
$ctx.ExecuteQuery()
$ctx.Load($web.Webs)
$ctx.ExecuteQuery()

$Properties = @{

Title = $site.Title
URL = $site.Url
SiteSizeLimitInMB = $site.StorageQuota
SiteUsageInMB = $site.StorageUsageCurrent
NoOfSubsites = $web.Webs.Count
SiteOwner = $site.Owner
LastContentModifiedDate = $site.LastContentModifiedDate
LastUserModifiedDate = $web.LastItemUserModifiedDate
SiteCollection = ‘Yes’
LastItemModifiedDate = $web.LastItemModifiedDate
}

$Global:webinfo += New-Object psobject -Property $properties

if ($web.Webs.Count -gt 0)
{
RecursiveWebs $ctx $web
}
}
catch
{
Write-Host $_ -ForegroundColor Red
$Properties1 = @{

Title = $site.Title
URL = $site.Url

}

$site401 += New-Object psobject -Property $properties1

}

}

$webinfo | Select-Object Title, URL, SiteSizeLimitInMB, SiteUsageInMB, LastItemModifiedDate,
LastUserModifiedDate, LastContentModifiedDate, NoOfSubsites,
SiteOwner, SiteCollection | Export-Csv -notypeinformation -Path ‘C:\temp\SPOinfo.csv’

$site401 | Select-Object Title, URL | Export-Csv -notypeinformation -Path ‘C:\temp\SPOinfo401.csv’

 

Advertisements

Comments (1)

SharePoint 2010: PowerShell Script to Create SiteCollection using Custom Template

Scenario:

We need to write PowerShell script to create site collection using custom template.

Resolution:

First, we need to save site as template. For this, “Site Settings” -> “Save site as template”. Enter site template name, say, testCustomtemplate. After saving, go to “Solution Gallery” and download the testCustomtemplate.wsp.

Second, add the wsp. For this, run SharePoint PowerShell and run following commands:

Add-SPSolution [Path to testCustomtemplate.wsp]

Install-SPSolution –identity testCustomtemplate.wsp

Third, run following script making appropriate changes:

$newSite = New-SPSite -Name [SiteCollectionName] -Url [URL] -OwnerEmail [OwnerMail] -OwnerAlias [OwnerLogin] -SecondaryOwnerAlias [SecondaryOwnerLogin]

Enable-SPFeature -Identity [FeatureGuid] -Url $newSite.Url

$rootWeb = $newSite.RootWeb

$rootWeb.ApplyWebTemplate(“[CustomTemplate]”)

You need to find values of two variables. One is “FeatureGuid” and other is “CustomTemplate”.

FeatureGuid can be found out by simply going to 14 hives, go for folder containing the name “WebTemplate” along with your solution name and copy feature ID. Like we have feature ID {e27e2916-5eb2-4a23-901b-fb3f386136bb}.

CustomTemplate can be manually created by concatenating the name of the solution and feature as under:

{e27e2916-5eb2-4a23-901b-fb3f386136bb}# testCustomtemplate

Or run following simple script after activating the feature on site collection:

$site = Get-SPSite [SiteCollectionURL]

$web = $site.RootWeb

$templates = $web.GetAvailableWebTemplates(1033) //1033 is Culture ID.

Foreach($temaplte in $templates)

{

$template.Name

}

Comments (2)

MOSS:Back up and Restore Site Collection / Sites Using STSADM Utility Export / Import

STSADM.EXE utility export and import operations are used to backup and restore site collections and sites. These operations are limited to site collections and sites only.  

STSADM.EXE is usually located at “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN”. No GUI interface for the STSADM utility is available. The old and trusted command line is used for the utility. 

The backup contains library content, list content, navigation, user information, security settings, personalize settings like views and content types and customization but does not contain alerts, workflows and properties.  

BACKUP 

For backup, we use export operation which has the following syntax: 

stsadm -o export 

-url <URL name>

-filename <export file name>

[-overwrite]

[-includeusersecurity]

[-haltonwarning]

[-haltonfatalerror]

[-nologfile]

[-versions] <1-4>

[-cabsize] <integer value>

[-nofilecompression]

[-quiet] 

Parameter Description
url URL of the site collection / site
filename Name of the backup file
overwrite Overwrite the already existed backup file
includeusersecurity Maintain the security settings
haltonwarning Stop the export operation when a warning occur
haltonfatalerror Stop the export operation when an error occur
nologfile No log file will be generated at the end of the export operation.
versions Values ranges from 1 to 41-          Default value, last major versions of the files and list items included.2-          The current version, either the major or the last minor version included.3-           Last major and last minor version of the files and list items included.4-          All versions of the files and list items included.
cabsize Value ranges from 1 to 1024. set the total size of cabinet file. Once  size limit is reached, another cabinet file is created.
nofilecompression Disable file compression. If compression is allowed, export operation can increase by 30%
quiet Export operation information will not be displayed and operation will end with success message.

The command that I use to run is  

stsadm –o export –url htpp://URL –filename E:\backup\test.cab –includeusersecurity –versions 4 –cabsize 1024 –nofilecompression  

This command will create a directory test.cab. 

RESTORE 

First you have to create an empty website to restore. This can be done using Microsoft Office SharePoint Designer 2007.

For this, open Microsoft Office SharePoint Designer 2007 and move from File menu to New and click on Web Site. In the New Dialog box, select Web Site tab, then select General and then Empty Web Site. Give the desired URL  in the text box at the bottom of the dialog box and click OK. Microsoft Office SharePoint Designer 2007 will create a new empty web site.  

To restore, we use import operation which has the following syntax: 

stsadm -o import

-url <URL name>

-filename <import file name>

[-includeusersecurity]

[-haltonwarning]

[-haltonfatalerror]

[-nologfile]

[-updateversions] <1-3>

[-nofilecompression]

[-quiet] 

Parameter Description
url URL of the site
filename Name of the restore file
includeusersecurity Maintain the security settings
haltonwarning Stop the export operation when a warning occur
haltonfatalerror Stop the export operation when an error occur
nologfile No log file will be generated at the end of the export operation.
updatversions Values ranges from 1 to 31       Default value, will add new version to the current file.2        Overwrite the file and all of its versions.3       Ignore the file if it exists of the destination.
nofilecompression Either enables or disables file compression in the import package. The import package is stored in the folder specified by the -filename parameter. It is recommended to use this parameter for performance reasons. If compression is enabled, it can increase the import process by approximately 30%.
quiet Export operation information will not be displayed and operation will end with success message.

The command that I use to run is  

stsadm –o import –url htpp://URL –filename E:\backup\test.cab –includeusersecurity –updateversions 3  –nofilecompression  

Exception: 

Error occurred while exporting the web http://site URL

Access is denied.(Eception from RESULT:0x8007005(E_ACCESSDENIED)) 

Reason: 

You are not the administrator of the site collection. 

Resolution: 

Add yourself as site administrator. For this, open SharePoint Central Administration. Move from “Application Management” to “Site collection administrators” under  “SharePoint Site Management”. Add yourself as administrator in the appropriate site collection. 

 

http://office.microsoft.com/download/afile.aspx?AssetID=AM102424831033

 

http://technet2.microsoft.com/Office/en-us/library/1178aa35-20b1-45b0-bcb6-4249aa34ea481033.mspx?mfr=true

 

http://technet2.microsoft.com/Office/en-us/library/65788bb9-0345-42c8-a216-e99e558b173d1033.mspx?mfr=true

 

 

Comments (14)

MOSS: Back up and Restore Web Sites Using Microsoft Office SharePoint Designer 2007

Microsoft Office SharePoint Designer 2007 is a good resource for backup and restore. It creates a content migration package (.cmp) for the web site.

The content migration package contains library content, list content, navigation, user information, security settings, personalize settings like views and content types and customization but content migration package does not contain alerts, workflows and properties.  

BACK UP WEB SITE

The first step is open the site in Microsoft Office SharePoint Designer 2007 and move from Site menu to Administration and click on Back Web Site.  

Backup Web Site dialog box will appear which will ask to include all the sub sites in the backup, do as appropriate and click OK.  

File Save dialog box will appear, guide it to the desired location after entering the name of the .cmp file and hit OK.  

Microsoft Office SharePoint Designer 2007 will take time to crate content migration package depending upon the size of the web site.  

RESTOR WEB SITE  

First we will create an empty web site for restoring. For this, open Microsoft Office SharePoint Designer 2007 and move from File menu to New and click on Web Site. 

In the New Dialog box, select Web Site tab, then select General and then Empty Web Site. Give the desired URL  in the text box at the bottom of the dialog box and click OK. Microsoft Office SharePoint Designer 2007 will create a new empty web site.  

Now, move from Site menu to Administration and click on Restore Web Site. Browse to the desired  content migration package (.cmp file) and click OK.

This will start restoring the site and success message  will appear at the end of the process.  

Exception: 

Error occurred while exporting the web http://site URL.

Access is denied.(Eception from HRESULT:0x8007005(E_ACCESSDENIED)) 

Reason: 

You are not the administrator of the site collection. 

Resolution: 

Add yourself as site administrator. For this, open SharePoint Central Administration. Move from “Application Management” to “Site collection administrators” under  “SharePoint Site Management”. Add yourself as administrator in the appropriate site collection.

Comments (9)