Saturday, September 27, 2014

Retrieve the List Item Count using PowerShell script


The following script will get the SharePoint List Item count for each list under each site collection. This script generated the output as CSV file.

Script:

cls
$ListsInfo = @()

$spsite= Get-SPSite -Limit All
foreach ($spsiteitem in $spsite)
{

$TotalItems = 0

ForEach ($Site in $spsiteitem.AllWebs)
{
    ForEach ($List in $Site.Lists)
    {
        $ListInfo=  New-Object System.Object
        $ListInfo | Add-Member -MemberType NoteProperty -Name "Site_Url" -Value $Site.Url -Force
        $ListInfo | Add-Member -MemberType NoteProperty -Name "List_Name" -Value $List.Title  -Force
        $ListInfo | Add-Member -MemberType NoteProperty -Name "Item_Count" -Value $List.ItemCount -Force
        $ListsInfo += $ListInfo
    }

}

$ListsInfo | Export-Csv -NoTypeInformation -Path "C:\ListData.csv"

}

Get the SharePoint Designer workflows using PowerShell script

The following script will get the SharePoint Designer workflows.

Script:

$site = Get-SPSite("http://sharepointsite/");
$site.AllWebs | foreach { $_.Lists | foreach { $_.WorkflowAssociations | foreach { write-host "Site:" $_.ParentWeb.Url ", List:" $_.ParentList.Title ", Workflow:" $_.Name} } }

Create and Set the quota template for site collections after moving to the SP2013 using PowerShell script


The following script will create and set the quota template for site collections after moving to the SP 2013. This script will generate the xml file.

Script:

cls
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
     Add-PSSnapin Microsoft.SharePoint.PowerShell;
}


function Get-SPQuotaTemplates
{
    # Prepare XML structure
    $xmlText =
@"
<?xml version="1.0" encoding="UTF-8" ?>
<QuotaTemplates AsOn="">
    <QuotaTemplate SiteUrl="Sample" Name="Sample" Value="0" QuotaID="0" StorageMaximumLevel="0" InvitedUserMaximumLevel="0" StorageWarningLevel="0" UserCodeWarningLevel="0" UserCodeMaximumLevel="0" UpgradedPersistedProperties="0" />
</QuotaTemplates>
"@

 
    # Read the XML string into an object
    $xmlDoc = [xml]$xmlText

    # Read the sample element
    $sampleQuotaTemplate = @($xmlDoc.QuotaTemplates.QuotaTemplate)[0]
    $service = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
    #Get all the SiteCollections
    $spsite= Get-SPSite -Limit All
    #Iterate through all the sitecollections
 
    foreach ($spsiteitem in $spsite)
    {
        $spsiteitem.Quota
        if($spsiteitem -ne $null)
        {   $flag=0
            #$service.QuotaTemplates
            foreach($serviceitem in $service.QuotaTemplates)
            {
             
                if($serviceitem.QuotaID -eq $spsiteitem.Quota.QuotaID)
                {
                    $quotaName=[string]($serviceitem.Name)
                    $tempQuotaTemplate=$serviceitem
                    $flag=1
                 
                }
             

            }
            if($flag -eq 0)
            {            
                    $quotaName="Individual Quota"
                    $tempQuotaTemplate=$spsiteitem.Quota
            }

       
                  $newQuotaTemplate = $sampleQuotaTemplate.Clone()
     
       #$newQuotaTemplate.Name = [string]($SPSite.Quota.QuotaID)
                  $newQuotaTemplate.SiteUrl=[string]$spsiteitem
         $newQuotaTemplate.Name =$quotaName.ToString()
       $newQuotaTemplate.Value = [string]$tempQuotaTemplate.Value
                  $newQuotaTemplate.QuotaID = [string]$tempQuotaTemplate.QuotaID
       $newQuotaTemplate.StorageMaximumLevel = [string](($tempQuotaTemplate.StorageMaximumLevel) / 1024 / 1024)
       $newQuotaTemplate.StorageWarningLevel = [string](($tempQuotaTemplate.StorageWarningLevel) /1024 / 1024)
       $newQuotaTemplate.UserCodeMaximumLevel = [string]$tempQuotaTemplate.UserCodeMaximumLevel
       $newQuotaTemplate.UserCodeWarningLevel = [string]$tempQuotaTemplate.UserCodeWarningLevel
                  $newQuotaTemplate.UpgradedPersistedProperties =[string]$tempQuotaTemplate.UpgradedPersistedProperties
                  $newQuotaTemplate.InvitedUserMaximumLevel=[string]$tempQuotaTemplate.InvitedUserMaximumLevel


        # Add the element to the QuotaTemplates node as a new child
        $xmlDoc.QuotaTemplates.AppendChild($newQuotaTemplate)
        }
    }

    # Remove Sample node
     $sample = $xmlDoc.QuotaTemplates.QuotaTemplate | Where-Object { $_.Name -eq "Sample" }
     $xmlDoc.QuotaTemplates.RemoveChild($sample)

    # Set date and time when generated
    $now = Get-Date
    $xmlDoc.QuotaTemplates.AsOn = [string]$now

    $xmlDoc.Save("C:\QTforSiteCol.xml")
    # Report completion
    Write-Host -f Green "The quota template information has been saved to C drive - QTforSiteCol.xml."
}

Get-SPQuotaTemplates

Update Managed Paths using PowerShell script

The following script will create the Managed Paths for the web application. This script needs the Input as CSV file. And CSV file should contains the Type,Name,WebApp as columns.
Type should contain for example - WildcardInclusion, ExplicitInclusion

Script:

$Name = @()
$Type = @()
$WebApp = @()

Import-Csv "D:\SPManagedPath.csv" |
    ForEach-Object {
        $Name += $_.Name
        $Type += $_.Type
                $WebApp += $_.WebApp
$inputNumber = Read-Host -Prompt "Please Enter to continue"  
    $Where = [array]::IndexOf($Type, $inputNumber)
    Write-Host "Name1: " $Name[$Where]
    Write-Host "Type2: " $Type[$Where]
    Write-Host "WebApp3: " $WebApp[$Where]
    New-SPManagedPath -RelativeURL $Name[$Where] -Explicit -WebApplication $WebApp[$Where]
    }

Update Primary and Secondary Site Collection Administrators using PowerShell script

The following script will update the Primary and Secondary Site collection administrators using powershell script. This script needs the Input as CSV file. And CSV file should contains the Sitecollectionurl,PrimaryAdmin,SecAdmin as columns.

Script:

#Get Site collection URL as a parameter  #param(  #[string] $filePath = $(Throw "Missing Input - CSV file path required with filename. Ex: C:\Solutions\SiteColAdmins.csv"), #required parameter  #[string] $LogFilePath = $(Throw "Missing Input - Path to create log file. Path al Ex: Ex: C:\Solutions\") #required parameter  #)  #Load SharePoint dll file  [void] [System.Reflection.Assembly]::Load(”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
#Load SharePoint Snap In
cls
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
     Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
$filePath = "C:\Solutions\SiteColAdmins.csv"
$csv_info = Import-Csv $filePath
#Logfile Name and Path
$LogFilePath = "C:\Solutions\"
$date = (get-date).ToString('yyyyMMdd')
$FileName = "UpdatePrimarySecondaryAdmin"
$FileName = $LogFilePath += $FileName += $date
#Creating Log file
if(!(Test-Path -Path "$FileName.txt"))
{
$file = New-Item -type file "$FileName.txt"
}
Write-Host "--Begin Process--"
Add-Content -Path "$FileName.txt" -Value "Begin Process"
#iterate Csv File
foreach ($line in $csv_info)
{
Write-Host "--starting update for site: " $line.Sitecollectionurl " PrimaryOwner: " $line.PrimaryAdmin " & SecondaryOwner: " $line.SecAdmin
Add-Content -Path "$FileName.txt" -Value $( "--starting update for site: " + $line.Sitecollectionurl + " PrimaryOwner: " + $line.PrimaryAdmin + " and SecondaryOwner: " + $line.SecAdmin)
#Get site collection
$urltest=$line.Sitecollectionurl
$sadmin=$line.SecAdmin
$padmin=$line.PrimaryAdmin
if($urltest -ne $null)
{
if($sadmin -ne $null -or $sadmin -ne " ")
{
    if($padmin -ne $null -or $padmin -ne "")
    {
Set-SPSite -Identity $urltest -SecondaryOwnerAlias $sadmin -OwnerAlias $padmin
Write-Host "Primary owner :" $padmin "is successfully added to " $urltest
Add-Content -Path "$FileName.txt" -Value $("Primary owner: " + $padmin + "is successfully added to " + $urltest)
Write-Host "Secondary owner :" $sadmin "is successfully added to " $urltest
Add-Content -Path "$FileName.txt" -Value $("Secondary owner: " + $sadmin + "is successfully added to " + $urltest)
    }
else
{
Write-Host "Secondary owner :" $sadmin "is Empty and not added to " $urltest
Add-Content -Path "$FileName.txt" -Value $("Secondary owner: " + $sadmin + "is not added to " + $urltest)
}


}
else
{
Write-Host "Primary owner :" $padmin "is Empty and not added to " $urltest
Add-Content -Path "$FileName.txt" -Value $("Primary owner: " + $padmin + "is not added to" + $urltest)
}
}
}
Add-Content -Path "$FileName.txt" -Value "End Process"
Write-Host "--End Process--"

Get the Primary and Secondary Site collection Administrator using PowerShell script

The following script will generate the text file which will give the list of Primary & Secondary Site collection Administrators for each web application.

Script:

Add-pssnapin microsoft.sharepoint.powershell -EA 0
$outputFile = "C:\\SCAdminsReport.txt"
Write-Host "This script will loop through all site collections in a web application and list the collection's URL, Primary Owner, and Secondary Owner"
$webapp = "http://sharepointsite/"
$Web = Get-SPWebApplication $webapp
$text = ""
$text | out-file $outputFile
foreach ($sites in $Web.sites) {
    $text = "-------------------------------------------"
    $text | out-file $outputFile -append
        $text = "Site: " + $sites.url
        $text | out-file $outputFile -append
    $text = "Primary Owner: " + $sites.owner
        $text | out-file "$outputfile" -append
    $text = "Secondary Owner: " + $sites.secondarycontact
        $text | out-file "$outputfile" -append
    $text = "-------------------------------------------"
        $text | out-file "$outputfile" -append
    }
Write-Host "-----END------"

Wednesday, April 17, 2013

Configuring Search in SharePoint 2010

In this article I am describing how to configure Search in SharePoint 2010.

1. Go to SharePoint Central Administration.

2. Click on Application management then select Manage Service application.
 

ConSerShare1.gif

3. Click New and select Search Service Application
 

ConSerShare2.gif

4. Give a name for your Service application.

5. Select Search Service account or register new Service account in the drop down.

6. Better create a new application pool for your Search service as shown below.
 

ConSerShare3.gif

7. Once done Click OK.
 

ConSerShare4.gif

8. It will take some time to configure the service.

9. Once configured correctly you will see the service created like below.
 

ConSerShare4.1.gif

10. Click on the Search Service Application 1 that we create now.

11. Select Content Source. 

ConSerShare5.gif

12. Click on the Local SharePoint Site.
 

ConSerShare6.gif

13. Add the Web applications that you need to put in Search Services as shown below.
 

ConSerShare7.gif

14. You have to configure Full and incremental crawl schedules in the preceding screen.

15. Now go back and start a Full crawl.
 

ConSerShare8.gif

16. You will get the following screen.
 

ConSerShare9.gif

17. Even though you have done all these steps you may get some error while searching "The search request was unable to connect to the Search Service".

18. To avoid this you have to perform the following steps.

19. Go to Application management and select Configure Application Association as shown below.
 

ConSerShare10.gif

20. Click on your application.

21. From the "Edit the following group of connections" drop down select Custom.

22. Associate your search service with your web application.

ConSerShare11.gif

23. If you done this step you may have to start the crawl once again.