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

Saturday, March 14, 2015

Get all the site collection with content DB details using powershell commands

As discussed earlier power shell commands are pretty powerful than SharePoint object model code. Some time we can't run SharePoint object model code in production environment like gathering site/server/DB details.

We can get sites and content DB details using following power shell commands 


$rootSite=New-Object Microsoft.SharePoint.SPSite("Web app URL")
$spWebApp = $rootSite.WebApplication 
foreach($site in $spWebApp.Sites) {
    
    write-output "$($site.RootWeb.Url) - $($site.ContentDatabase)"     
  
    $site.Dispose() 


Sunday, November 2, 2014

SharePoint back basics – move site collection to another content Database using PowerShell commands

Yes, we can move SharePoint site collection form one content DB to another Content database. But before moving the database we need to check following things,
  • New content database should be exists on the same server and it needs to be under the same web application.
  • The account used to move the site collection should be WSS_ADMIN_WPG group and account need to have db_owner permissions.

Before moving the content Db we have verify the size of the DB by using following command,

$spaceUsedinDB = (Get-SPSiteAdministration -Identity (SiteCollection URL).DiskUsed
$spaceUsedinDB

To move the site collection to the new content DB create a new content DB in SharePoint central Admin by navigating to Application management -> Manage Content Database -> Create new Content Database




Run following command in SharePoint management shell,

Move-SPSite SiteCollection URL -DestinationDatabase Target_Content_DB_Name

This operation will take time depending on the site collection size. 

Thursday, July 24, 2014

SharePoint – Delete Orphaned sites using PowerShell commands

We can delete the orphaned site in SharePoint environment that we are trying to provision the project server application. To remove orphaned site we have to un-provisioned and then delete the site.

We can delete the site by using following PowerShell commands,

Get SharePoint service application by using Get-SPServerviceApplication command
We can see the list of GUID’s. Get the service application specific to the orphaned site by using get-spserviceapplication command

$serviceApp = Get-SpServiceapplication | ? {$_.Id -eq "GUID of the Service App"}

Get the Site collection by using the service app

 $siteCollection = $serviceApp.SiteCollection

Get the site from Site Collection and delete the site by using the following commands,

$site = $siteCollection.Sitecollection | where {$_.SiteID -eq "< Guid>"}
$site.Delete()


Wednesday, April 9, 2014

PowerShell Scheduled Data Refresh – Call to Excel Services Returned an error

In SharePoint Power Pivot data Automatic refresh from excel services, I got an error saying that “Power Pivot Scheduled Data Refresh – Call to Excel Services Returned an error” as shown the image below



By digging into the issue I have found that I don’t have permissions for Power Pivot service. To fix the issue we have to add the permissions for Power Pivot. To add we need to give the account running Power Pivot Full Control to the Web app under the Policy for Web Application.


Hope this helps.

Tuesday, March 18, 2014

Upgrade SharePoint 2010 classic mode web application to SharePoint 2013 claims mode using PowerShell commands

While working with SharePoint 2010 to 2013 migration I have to migrate SharePoint 2010 classic mode 2013 claims mode because we don’t have classic mode in SharePoint 2013. To do that I have upgraded SharePoint 2010 site to use claims mode authentication using PowerShell commands and restored the DB in SP 2013 server.

Now I ran: Test-SPContentDatabase” command to check the upgrade status. I got an error saying that there is inconsistency between the authentication modes. So I have reverted the claims mode authentication web app to classic mode and created a Web application in SharePoint 2013 using classic mode using following command

New-SPWebApplication -Name "Web application name" -ApplicationPool " Web application AppPool" -AuthenticationMethod "NTLM" -ApplicationPoolAccount (Get-SPManagedAccount "Application Pool account") -Port Port Number -URL "URL of the web application"

Now I took the classic mode SP 2010 web application backup and restored in SP 2013 web application. By running “Test-SPContentDatabase” command I got no issues. Now mount the database using “Mount-SPContentDatabase” command

Mount-SPContentDatabase ContentDB Name -DatabaseServer DBServerName -WebApplication Web Application URL

Finally we have to convert the web application from classic mode to claimant mode by using “Convert-SPWebApplication” command

Convert-SPWebApplication -Identity "WebApp URL" -To Claims –RetainPermissions -Force

Tuesday, March 11, 2014

Change default home/welcome page in SharePoint site using PowerShell commands

We can change SharePoint default home page in different ways as using Site settings if publishing feature already enabled, SharePoint object model code, Using SharePoint designer and PowerShell commands.
We can change the home page by running following PowerShell commands,

Get the Site details by using Get-SPSite command and web by using OpenWeb() method.

$objSite = Get-SPSite SiteURL
$objWeb = $objSite.OpenWeb(“Sub site”)

Get the root folder for the web by using RootFolder property

$rootFolder = $objWeb.RootFolder

Change the home page by assigning Welcomepage property as shown below

$rootFolder.Welcomepage = “SitePages/SureshHomePage.aspx
$rootFolder.update()

After updating the page, we have to dispose the site and web objects because that objects are created newly.

$objWeb.dispose()
$objSite.dispose()

By combing the all the commands we can see the script as

$objSite = Get-SPSite SiteURL
$objWeb = $objSite.OpenWeb(“Sub site”)
$rootFolder = $objWeb.RootFolder
$rootFolder.Welcomepage = “SitePages/SureshHomePage.aspx
$rootFolder.update()
$objWeb.dispose()
$objSite.dispose()