Friday, June 26, 2015

SharePoint Feature Installation, Activation, Deactivation, and Uninstallation using PowerShell

To install a SharePoint feature with PowerShell
Install-SPFeature FeatureFolderName

To activate a feature
Enable-SPFeature FeatureFolderName -Url http://server/site/subsite

To deactivate a feature
Disable-SPFeature FeatureFolderName -Url http://server/site/subsite

To uninstall a feature
Uninstall-SPFeature FeatureFolderName

Examples:

Activate site collection feature
$site = Get-SPSite http://sp2010
Enable-SPFeature -Identity “FeatureName” -Url $site.Url
$site.Dispose()

Activate site feature
$web = Get-SPWeb http://sp2010
Enable-SPFeature -Identity “FeatureName” -Url $web.Url
$web.Dispose()

Activate site collection features for all site collections in a Web Application
$webApp = Get-SPWebApplication -Identity http://sp2010
$webApp | Get-SPSite -limit all | ForEach-Object {Enable-SPFeature -Identity “FeatureName” -Url $_.Url}

How to Deactivate a SharePoint feature using PowerShell or STSADM

To Disable a SharePoint Feature, you must first determine the scope of the feature. If the scope is Web-based or is a site collection scope, the URL parameter is required. However, if the scope is farm-based, the URL parameter is not required.

Syntax - PowerShell

Disable-SPFeature [-Identity] <SPFeatureDefinitionPipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-Force <SwitchParameter>] [-Url <String>] [-WhatIf [<SwitchParameter>]]

This example disables the "MyCustom" Web site scoped feature at http://somesite.
Disable-SPFeature -identity "MyCustom" -URL http://somesite

This example disables all features in the subsite at http://somesite/myweb.
$w = Get-SPWeb http://somesite/myweb | ForEach{ $_.URL }
Get-SPFeature -Web $w |%{ Disable-SPFeature -Identity $_ -URL $w}

Syntax - STSADM

stsadm -o deactivatefeature
   -filename
   -name <feature folder>
   -id <feature ID>
   [-url] <URL name>
   [-force]

Parameter
Value
Description
filename
A valid file path, such as "MyFeature\Feature.xml"
Path to feature must be a relative path to the 14\Template\Features directory. Can be any standard character that the Windows system supports for a file name.
name
Name of the feature directory, such as “MyFeature”
Name of the feature folder located in the 14\Template\Features directory
id
A valid GUID, e.g.  “11d186e-7306-4902-a825-0eb7609e9280”
GUID that identifies the feature to activate
url
A valid URL, such as http://server_name
URL of the Web application, site collection, or Web site to which the feature is being activated


How to Activate a SharePoint feature using PowerShell or STSADM

To Enable a SharePoint Feature, you must first determine the scope of the feature. If the scope is Web-based or is a site collection scope, the URL parameter is required. However, if the scope is farm-based, the URL parameter is not required.

Syntax - PowerShell

Enable-SPFeature [-Identity] <SPFeatureDefinitionPipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-CompatibilityLevel <Int32>] [-Confirm [<SwitchParameter>]] [-Force <SwitchParameter>] [-PassThru <SwitchParameter>] [-WhatIf [<SwitchParameter>]]

This example enables the "MyCustom" site scoped SharePoint Feature at http://somesite.
Enable-SPFeature -identity "MyCustom" -URL http:// sitename

This example enables all SharePoint Features in the subsite at http://somesite/myweb.
$w = Get-SPWeb http://somesite/myweb | ForEach{ $_.URL }
Get-SPFeature -Web $w |%{ Enable-SPFeature -Identity $_ -URL $w}

Syntax - STSADM

stsadm -o activatefeature
   {-filename <relative path to Feature.xml> | -name <feature folder> | -id <feature ID>}
   [-url] <URL name>
   [-force]

Parameter
Value
Description
filename
A valid file path, such as "MyFeature\Feature.xml"
Path to feature must be a relative path to the 14\Template\Features directory. Can be any standard character that the Windows system supports for a file name.
name
Name of the feature directory, such as “MyFeature”
Name of the feature folder located in the 14\Template\Features directory
id
A valid GUID, e.g.  “11d186e-7306-4902-a825-0eb7609e9280”
GUID that identifies the feature to activate
url
A valid URL, such as http://server_name
URL of the Web application, site collection, or Web site to which the feature is being activated

Note : If you try to use the Url parameter on a farm-scoped feature, you receive the following error message:
The feature ‘<feature name>’ applies to the entire farm; the Url parameter cannot be used with farm-scoped features.

Thursday, June 18, 2015

How to Remove a SharePoint subsite through PowerShell

The Remove-SPWeb cmdlet completely deletes the Web specified by the Identity parameter.
Note: Deleting the top level Web site of a site collection causes the entire site collection to be removed.

Syntax

Remove-SPWeb [-Identity] <SPWebPipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-Recycle <SwitchParameter>] [-WhatIf [<SwitchParameter>]]

Example

Remove-SPWeb http://sitename/subsite

This example completely deletes a subsite.

Import sites, lists, or document libraries in SharePoint

We can import a site, list, or document library in SharePoint by PowerShell.
Start the SharePoint Management Shell.

Syntax

Import-SPWeb [-Identity] <SPWebPipeBind> -Path <String> [-ActivateSolutions <SwitchParameter>] [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-Force <SwitchParameter>] [-HaltOnError <SwitchParameter>] [-HaltOnWarning <SwitchParameter>] [-IncludeUserCustomAction <None | All>] [-IncludeUserSecurity <SwitchParameter>] [-NoFileCompression <SwitchParameter>] [-NoLogFile <SwitchParameter>] [-UpdateVersions <Append | Overwrite | Ignore>] [-WhatIf [<SwitchParameter>]]

Example
Import-SPWeb http://site -Path export.cmp -UpdateVersions Overwrite
This example imports the contents of export.cmp into a site at http://site, overwriting the versioned content on the site with the contents of the export.cmp file.


Export sites, lists, or document libraries in SharePoint

We can export a site, list, or document library in SharePoint by using the SharePoint Central Administration website or Windows PowerShell.

Use Windows PowerShell to export a site, list, or document library in SharePoint
To export a site, list or document library by using Windows PowerShell you need to have the below permissions :
securityadmin fixed server role on the SQL Server instance.
db_owner fixed database role on all databases that are to be updated.

1) Start the SharePoint Management Shell.

Syntax

Export-SPWeb -Identity <SiteURL> -Path <Path and File Name> [-ItemUrl <URL of Site, List, or Library>] [-IncludeUserSecurity] [-IncludeVersions] [-NoFileCompression] [-GradualDelete] [-Verbose]

Use Central Administration to export a site, list, or document library in SharePoint

Only export one site, list, or document library at a time.
To export a site, list, or document library by using Central Administration, verify that the user account that is performing this procedure is a member of the Farm Administrators group.

1) Start SharePoint Central Administration.

2) In Central Administration, on the home page, click Backup and Restore.

3) On the Backup and Restore page, in the Granular Backup section, click Export a site or list.

4) On the Site or List Export page, in the Site Collection section, select the site collection from the Site Collection list, and then select the site from the Site list.

5) If you are exporting a site, skip this step, Select the list or document library from the List list.

6) In the File Location section, in the Filename box, type the UNC path of the shared folder and the file to which you want to export the list or document library. The file name must use the .cmp extension.

7) If the file already exists and you want to use this file, select the Overwrite existing files check box. Otherwise, specify a different file name.

8) If you want to export all the security and permissions settings with the list or library, in the Export Full Security section, select the Export full security check box.

9) If you want to specify which version of the list or library to export, select one of the following versions from the Export versions list: All Versions , Last Major , Current Version , Last Major and Last Minor


10) When you have specified the settings that you want, click Start Export.

SharePoint Major Version and Minor Version

A major version is usually one that represents a milestone, such as completion of an outline or a chapter. Major versions are numbered with whole numbers, such as 3.0, 4.0, and so on.

A minor version represents interim check-ins while a particular file is under development. Minor versions are numbered with decimals, such as 4.1, 4.2, 4.3, and so on.

In many organizations, versioning is set up so that only the owner of the file and people who can approve items can see minor versions. In others, it is set up so that anyone who can edit files in the library, or anyone who has Read permission to the library, can see all versions.

Note: Major and minor versions are available in libraries, but not in lists.
Limiting the number of versions is generally a good practice. It means you can conserve space on the server and reduce clutter for users. But, if your organization is required to save all versions for legal or other reasons, do not apply any limits.
  • When you check out a file in a versioning-enabled library, a new version is created every time you check it back in. And, if major and minor versions are part of the configuration of your library, you can designate, at check-in, which type of version you are checking in. In libraries where check-out is required, versions are only created upon check-in.


  • In libraries where check-out is not required, a new version is created the first time you save after opening the file. Each subsequent save overwrites the version that you created with the first save. If you close the application and then reopen the document, the first save will, once again, produce a version. This can cause the number of versions to proliferate very rapidly.

How to View a file or item from previous version

If you need to view an older version of an item or file, you can select the older version and “view” it so that it becomes the current version.

1. Navigate to the list or library where your item or file is located.
2. Hover over the item or file for which you want to manage versions until you see a drop-down arrow.
3. Click the drop-down arrow and select Version History.
4. Hover over the version that you want to view and select the document.
5. This will display the document with that particular version.

How to Delete a previous version

If you need to make sure that no one can read a version that has inaccurate or otherwise troublesome information, you can delete it.

1. Navigate to the list or library where your item or file is located.
2. Hover over the item or file for which you want to manage versions until you see a drop-down arrow.
3. Click the drop-down arrow and select Version History.
4. Hover over the version that you want to delete until you see a drop-down arrow.
5. Click the drop-down arrow and select Delete.
6. When you are prompted to confirm the deletion, click OK.


Note: When you delete a version, it is sent to the Recycle Bin, where you, or another person who has the necessary permissions, can recover it. If you do not see the Recycle Bin on your site, your server administrator might have disabled it.

How to Restore a file or item from previous version

If you need an older version of an item or file, you can select the older version and “restore” it so that it becomes the current version.

1. Navigate to the list or library where your item or file is located.
2. Hover over the item or file for which you want to manage versions until you see a drop-down arrow.
3. Click the drop-down arrow and select Version History.
4. Hover over the version that you want to restore until you see a drop-down arrow.
5. Click the drop-down arrow and select Restore.
6. When you are prompted to confirm the restoration as your current version, click OK.