Showing posts with label SharePoint PowerShell. Show all posts
Showing posts with label SharePoint PowerShell. Show all posts

Thursday, 6 March 2014

Create site in a new Content Database Sharepoint 2010


      whenever i tried to create a new site in the server it takes up only default content database. I was looking after to create a new site in a separate content database. Unfortunately when i try to create a new site it does not ask me an option to choose the content database that i would like to create the site.

img

I dig up and found that this could be achieved using powershell.

First create a content database using central administration.
To create,

  1)  Central Administration -> Application Management -> Manage Content Databases under Databases.




2) You can see a content database that is already available by default. Here you have to add a new content database. Click Add a Content database.




3) You could rename the database name. Provide appropriate name for your database. Click ok.




4) Now you could see a new content database is created.

  To create a new site in that particular created content database use this following script in posershell.


Powershell Command:

New-SPSite http://yourServerName/sites/YourSite -OwnerAlias "ServerAdministratorUserName" -ContentDatabase ContentDatabaseName -Name "SiteNametobeCreated" -Description "DescriptionabouttheSite" -Template "STS#0"

On successful creation of site over the created database, you will receive this created url.


Thursday, 13 February 2014

Server Dependency error (Missing Feature)


          When we redeploy wsp files in sharepoint server, it will check for its previous version using the feature ID. The old versions feature id will not be available since wsp files has been removed. Though the files have been removed its id will be available in the server.

           It will throw an exception and this exception will be stored in the configuration section. When site content backup is restored this error transfers to the other server too. This exceptions can be removed by using power shell command.

          Go to the following location. Central Administration --> Monitoring --> Review Problems and Solutions under Health Analyzer. Under category configuration click Missing Server side dependencies. There you will find [Missing Feature] type. Now go to Sharepoint Power Shell. and do the following.

PowerShell Remove Features in SharePoint because of Health Issue For "Missing Feature"


Run The below power shell Method in SharePoint Management shell.

 function Remove-SPFeatureFromContentDB($ContentDb, $FeatureId, [switch]$ReportOnly)
{
    $db = Get-SPDatabase | where { $_.Name -eq $ContentDb }
    [bool]$report = $false
    if ($ReportOnly) { $report = $true }
   
    $db.Sites | ForEach-Object {
       
        Remove-SPFeature -obj $_ -objName "site collection" -featId $FeatureId -report $report
               
        $_ | Get-SPWeb -Limit all | ForEach-Object {
           
            Remove-SPFeature -obj $_ -objName "site" -featId $FeatureId -report $report
        }
    }
}
function Remove-SPFeature($obj, $objName, $featId, [bool]$report)
{
    $feature = $obj.Features[$featId]
   
    if ($feature -ne $null) {
        if ($report) {
            write-host "Feature found in" $objName ":" $obj.Url -foregroundcolor Red
        }
        else
        {
            try {
                $obj.Features.Remove($feature.DefinitionId, $true)
                write-host "Feature successfully removed from" $objName ":" $obj.Url -foregroundcolor Red
            }
            catch {
                write-host "There has been an error trying to remove the feature:" $_
            }
        }
    }
    else {
        #write-host "Feature ID specified does not exist in" $objName ":" $obj.Url
    }
}



To run only a report (-ReportOnly property):
Remove-SPFeatureFromContentDB -ContentDB "Content_DBName" -FeatureId "e8389ec7-70fd-4179-a1c4-6fcb4342d7a0" –ReportOnly

To remove the feature from all sites, site collections in the db run (no -ReportOnly property):
Remove-SPFeatureFromContentDB -ContentDB "Content_DBName" -FeatureId "8096285f-1473-45c7-85b7-f745e5b2cf29"  


   This will work only for [Missing Feature] issues.

Friday, 27 September 2013

PowerShell script to delete all items in a List



Deleting items from your list can be done in a easier way using the shell script. 
This is much easier when compared to deleting items from the browser. 

1) Copy & paste the following script in a notepad. 

2) Provide your site name mentioned at $SITEURL = "http://your server"

3) Provide your list name as it in browser mentioned at $oList = $web.Lists["Your List"];

4) Run Sharepoint 2010 Management Shell as administrator.

5) Copy paste the script from notepad and press enter.

6) Now all the items at particular list will be deleted.


$SITEURL = "http://your server"

$site = new-object Microsoft.SharePoint.SPSite ( $SITEURL )
$web = $site.OpenWeb()
"Web is : " + $web.Title

$oList = $web.Lists["Your List"];

"List is :" + $oList.Title + " with item count " + $oList.ItemCount

$collListItems = $oList.Items;
$count = $collListItems.Count - 1

for($intIndex = $count; $intIndex -gt -1; $intIndex--)
{
        "Deleting : " + $intIndex
        $collListItems.Delete($intIndex);
}