Showing posts with label power shell. Show all posts
Showing posts with label power shell. Show all posts

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 Managed Accounts error: Managed Account could not be deleted because other objects depend on it.

After deleting all the service applications and managed account from SharePoint server by using following PowerShell commands,

Get-SPManagedAccount | Where-Object {$_.UserName -eq "Domain\Username"} | Remove-SPManagedAccount

By running the command I got an error saying that,

Remove-SPManagedAccount : An object in the SharePoint administrative framework, “SPManagedAccount Name=managed-account-S-1-5-21-2912393494-653453454-43454533245-4324″, could not be deleted because other objects depend on it. 

We can see this error because the service error we are going to delete is having dependencies. In my case iam using same account for User Profile Service.

By using following commands, we can release the dependencies on the service account.

Get-SPServiceApplicationPool | Where-Object {$_.Name -eq "User Profile Service"} | Remove-SPServiceApplicationPool

After running the command we have to delete the account by running the following command,

Get-SPManagedAccount | Where-Object {$_.UserName -eq "Domain\Username"} | Remove-SPManagedAccount


Hope this helps.

Thursday, January 9, 2014

Creating content sources in SharePoint using PowerShell commands

We can create the content sources based on the content types as per the requirements. Content types for content sources might be SharePoint site or web or Files that associated with in SharePoint environment.
To create a content source based on a web content type we can use the following script,

$contentSourceName = “Name of the content source to be configured”;
$siteUrl = “URL of the Site”;
$ssa=Get-SPEnterPriseSearchServiceApplication -Identity $xmlData.SSAName;
$ssaContent = new-object Microsoft.Office.Server.Search.Administration.Content($ssa);
if($myType -eq “Web”){

$webContentSource=$ssaContent.ContentSources.Create([Microsoft.Office.Server.Search.Administration.WebContentSource], $contentSourceName);

$webContentSource.startAddresses.Add($siteUrl);
}

Here $myType is content type

To create a content source based on a SharePoint content type we can use the following script,

$contentSourceName = “Name of the content source to be configured”;
$siteUrl = “URL of the Site”;
$ssa=Get-SPEnterPriseSearchServiceApplication -Identity $xmlData.SSAName
$ssaContent = new-object Microsoft.Office.Server.Search.Administration.Content($ssa)
if($myType -eq “SharePoint”){

$sharepointContentSource=$ssaContent.ContentSources.Create([Microsoft.Office.Server.Search.Administration.SharePointContentSource], $contentSourceName);

$sharepointContentSource.startAddresses.Add($siteUrl);
}

To create a content source based on a File content type we can use the following script,

$contentSourceName = “Name of the content source to be configured”;
$siteUrl = “URL of the Site”;
$ssa=Get-SPEnterPriseSearchServiceApplication -Identity $xmlData.SSAName
$ssaContent = new-object Microsoft.Office.Server.Search.Administration.Content($ssa)
if($myType -eq “File”){

$fileContentSource=$ssaContent.ContentSources.Create([Microsoft.Office.Server.Search.Administration.SharePointContentSource], $contentSourceName);

$fileContentSource.startAddresses.Add($siteUrl);
}