Search This Blog

Showing posts with label Powershell. Show all posts
Showing posts with label Powershell. Show all posts

Tuesday, June 28, 2016

How to add a user to Web Application User Policy using PowerShell

To add a user to web application user policy using PowerShell , use the below PowerShell script

$userOrGroup = "i:0#.w|domain\user"
$displayName = "User-NTLM"

$webApp = Get-SPWebApplication("URL")
$policy = $webApp.Policies.Add($userOrGroup, $displayName)
$policyRole = $webApp.PolicyRoles.GetSpecialRole([Microsoft.SharePoint.Administration.SPPolicyRoleType]::FullControl)
$policy.PolicyRoleBindings.Add($policyRole)
$webApp.Update() 

Thursday, March 3, 2016

PowerShell to get the details of Content Sources in the SharePoint Search Service Application

This example retrieves the default content source for the search service application.

$ssa = Get-SPEnterpriseSearchServiceApplication

Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $ssa


Name                           Id    Type                CrawlState CrawlCompleted     
----                               --      ----                   ---------- --------------     
Local SharePoint sites     1     SharePoint           Idle                          
Content Source 1           17    SharePoint           Idle       2/2/2016 2:58:46 PM
Content Source 2            6     SharePoint           Idle       2/2/2016 1:57:00 PM
Content Source 3            12   SharePoint           Idle       2/2/2016 11:57:40 AM
Content Source 4            14   SharePoint           Idle       2/2/2016 11:58:14 AM
Content Source 5            15   SharePoint           Idle       2/2/2016 3:27:58 PM



Monday, January 18, 2016

Common Office Web Apps PowerShell commands

Get-SPWOPIBinding
The Get-SPWOPIBinding returns a list of bindings that were created by using New-SPWOPIBinding on the current SharePoint farm.

Get-SPWOPIBinding

Remove-SPWOPIBinding
The Remove-SPWOPIBinding removes all bindings on the current SharePoint farm.

Remove-SPWOPIBinding -All:$true

New-SPWOPIBinding
The New-SPWOPIBinding creates bindings for all the applications and file name extensions that the WOPI application supports on the current SharePoint farm

New-SPWOPIBinding -ServerName "Server.corp.Contoso.com"


Related Posts � 1, 2

Tuesday, July 14, 2015

How to delete a corrupted SharePoint list using PowerShell

$web = get-spweb -Identity http://sp2010
$list = $web.lists["corrupted list name"]
$list.AllowDeletion = $true
$list.Update()
$list.Delete()

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-SPWebcmdlet 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.

Friday, May 1, 2015

Powershell to list Content Database details for SharePoint Site Collection

Get the Content Database details for SharePoint Site Collection

Get-SPContentDatabase -Site 'http://sharepointsitecollectionurl/'


Id               : xxx1404-b716-xxxx-ba76-9746xxxx                                                                  
Name             : xxx                                                                                                       
WebApplication   : xxx                                                                                                                
Server           :           xxx                                                                                                       CurrentSiteCount : 1

Powershell to list all SharePoint Site Collections and subsites a web application

Get list of SharePoint Site Collections and SubSites

Get-SPSite 'http://sharepointwebapplicationurl/' | Get-SPWeb -Limit All

Powershell to list all SharePoint Site Collections in a web application

Get list of SharePoint Site Collections

Get-SPSite  -Limit All

Powershell to list all SharePoint databases and their sizes

Get list of SharePoint databases and their sizes

Get-SPDatabase | Sort-Object disksizerequired -desc | %{write-host  "Size: $($_.disksizerequired/1mb)MB - Database: $($_.Name)"}

The result will be listed down in the below format.

Size: 5237MB - Database: SharePoint_Config
Size: 3455MB - Database: UsageDB
Size: 2261MB - Database: SharePoint_AdminContent
Size: 204MB - Database: WebAnalyticsStagerDB
Size: 172MB - Database: Sync DB
Size: 155MB - Database: SearchDB_PropertyStore
.
.
.
.
.
Size: 6MB - Database: BusinessDataCatalogDB
Size: 3MB - Database: SecureStoreServiceAppDB
Size: 2MB - Database: StateServiceDB
Size: 2MB - Database: PerformancePointDB

Powershell to list all SharePoint Content Databases in the SharePoint Farm

Get list of all SharePoint Content Databases in the SharePoint Farm

Get-SPContentDatabase

Powershell to list all SharePoint Databases in the SharePoint Farm

Get list of SharePoint Databases in the SharePoint Farm

Get-SPDatabase

Monday, April 13, 2015

How to create a SharePoint State Service application through PowerShell

If you configure the SharePoint service applications manually and not run the configuration wizard, you will miss creating the State Service Application as it is not listed down as a service application option in Central Administration -> Manage Service applications page. ( This Service Application is not available for creation in the New dialog in Central Administration, Manage Service Application)

So it should be created through PowerShell. Below are the commands to create one :

$serviceApp = New-SPStateServiceApplication -Name "State Service Application"
New-SPStateServiceDatabase -Name "SharePoint_Service_State" -ServiceApplication $serviceApp
New-SPStateServiceApplicationProxy -Name "State Service Application Proxy" -ServiceApplication $serviceApp -DefaultProxyGroup



Friday, April 10, 2015

SharePoint Search Service Application Creation through PowerShell

Search service Application can be created and configured through Central Administration and PowerShell as well. The below commands creates the Search Service Application and the associated databases.Further configuration can be done from Central Administration. The main purpose of doing this is to create search related databases without GUID�s.

$SSADB = "SearchDB�
$SSAName = "Search Service Application"
$SVCAcct = "Domain\UserName"
$SSI = Get-SPEnterpriseSearchServiceInstance -local

1. Start Services search services for SSI
Start-SPEnterpriseSearchServiceInstance -Identity $SSI

2. Create an Application Pool.
$AppPool = New-SPServiceApplicationPool -Name $SSAName" AppPool" -account $SVCAcct

3. Create the SearchApplication and set it to a variable
$SearchApp = New-SPEnterpriseSearchServiceApplication -Name $SSAName -Applicationpool $AppPool -DatabaseName $SSADB

4. Create search service application proxy
$SSAProxy = New-SPEnterpriseSearchServiceApplicationProxy -Name $SSAName" ApplicationProxy" -Uri $SearchApp.Uri.AbsoluteURI

5. Provision Search Admin Component.
Set-SPEnterpriseSearchAdministrationComponent -SearchApplication $SearchApp -SearchServiceInstance $SSI

The database names would be as below by running the above PowerShell.

Administration Database: SearchDB
Crawl Database: SearchDB_CrawlStore
Property Database: SearchDB_PropertyStore

Thursday, April 9, 2015

How to create a SharePoint Usage and Health Data Collection Service Application through PowerShell

Usage and Health Data Collection Service Application collects Data about Usage and Health of your farm. This information is used for Health Monitoring and this is also required for running the Web Analytics Service. If you do not have a Usage and Health Data Collection Service Application or your Usage and Health Data Collection Proxy is stopped, you will not see any data in the Web Analytics Report.

You cannot create Usage and Health Data Collection Service Application from Central Admnistration.
You have to use PowerShell for this :

New-SPUsageApplication -Name �UsageAppName� -DatabaseServer �DBServerName� -DatabaseName �DBName�

$Usage = Get-SPServiceApplicationProxy | where {$_.TypeName -eq �Usage and Health Data Collection Proxy�}

$Usage.provision()


How to create a new content database for a web application

New-SPContentDatabase

The New-SPContentDatabase cmdlet creates a new content database and attaches it to the specified Web application.

New-SPContentDatabase [-Name] <String> [-WebApplication] <SPWebApplicationPipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-AssignNewDatabaseId <SwitchParameter>] [-ChangeSyncKnowledge <SwitchParameter>] [-ClearChangeLog <SwitchParameter>] [-Confirm [<SwitchParameter>]] [-DatabaseCredentials <PSCredential>] [-DatabaseServer <String>] [-MaxSiteCount <Int32>] [-WarningSiteCount <Int32>] [-WhatIf [<SwitchParameter>]]

Example

New-SPContentDatabase "MyDatabase" -DatabaseServer "MyServer" -WebApplication http://sitename


Tuesday, April 7, 2015

Backup a SharePoint Site

Backup SharePoint Site
Backup-SPSite http://sitename -Path E:\Backup\site_name.bak

NAME
    Backup-SPSite

SYNOPSIS
    Performs a backup of a site collection.

SYNTAX
    Backup-SPSite [-Identity] <SPSitePipeBind> -Path <String> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-Force <SwitchParameter>] [-NoSiteLock <SwitchParameter>] [-UseSqlSnapshot <SwitchParameter>] [-WhatIf [<SwitchParameter>]] [<CommonParameters>]

DESCRIPTION

The Backup-SPSite cmdlet performs a backup of the site collection when the Identity parameter is used. By default, the site collection will be set to read-only for the duration of the backup to reduce the potential for user activity during the backup operation to corrupt the backup. 

Restore a SharePoint site to a specific database

Restore a SharePoint site
Restore-SPSite http://sitename -Path "E:\Backup\file.bak" -Force

Restore a SharePoint site to a specific database

Restore-SPSite http://sitename -Path "E:\Backup\file.bak" -Force -DatabaseName "Database"

NAME
    Restore-SPSite

SYNOPSIS
    Restores a site collection.

SYNTAX
  Restore-SPSite [-Identity] <String> -Path <String> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-ContentDatabase <SPContentDatabasePipeBind>] [-Force <SwitchParameter>] [-GradualDelete <SwitchParameter>] [-HostHeaderWebApplication <String>] [-WhatIf [<SwitchParameter>]] [<CommonParameters>]

Restore-SPSite [-Identity] <String> -Path <String> [-AssignmentCollection <SPAssignmentCollection>] [-Confirm [<SwitchParameter>]] [-DatabaseName <String>] [-DatabaseServer <String>] [-Force <SwitchParameter>] [-GradualDelete<SwitchParameter>] [-HostHeaderWebApplication <String>] [-WhatIf [<SwitchParameter>]] [<CommonParameters>]

DESCRIPTION

The Restore-SPSite cmdlet performs a restoration of the site collection to a location specified by the Identity parameter. A content database may only contain one copy of a site collection. If a site collection is backed up and restored to a different URL location within the same Web application, an additional content database must be available to hold the restored copy of the site collection.
Propellerads