Copy Users to another Site Collection

Hey Folks,

Please find below script to copy users from one site collection to another in SharePoint User Group.


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$SourceWebURL = "YourSourceSiteUrl"
$TargetWebURL = "YourTargetedSiteUrl"
$SourceGroupName="YourSourceGroupName"
$TargetGroupName="YourTargetGroupName"

$SourceWeb = Get-SPWeb $SourceWebURL
$TargetWebURL= Get-SPWeb $TargetWebURL

$SourceGroup = $SourceWeb.groups | where {$_.name -eq $SourceGroupName }
$TargetGroup = $TargetWebURL.groups | where {$_.name -eq $TargetGroupName }

foreach ($user in $SourceGroup.users)
{
$TargetGroup.AddUser($user)
Write-Host "Copied $user from $SourceGroup to $TargetGroup"
}

Happy SharePointing ūüôā

Advertisements

Handle SharePoint large list (throttling)

Hello Folks

Most of the Developers face the throttling issue while bind and load the data from list to gridview. especially in those scenarios when you have thousands or millions of records in list. in order to protect the performance of the farm as a whole. Limits are applied on a per-Web application basis and are typically managed through the Web application settings in Central Admin. but you can handle the throttling issue while fetching the records from large list, i have tested this code on 10,000 records.

SPWeb web = SPContext.Current.Web;
SPList list = web.Lists["yourList"];
SPQuery query = new SPQuery();
query.QueryThrottleMode = SPQueryThrottleOption.Override;
SPListItemCollection items = list.GetItems(query);

The SPQueryThrottleOption enumeration has three values: Default, Override, and Strict. If you use the default value, the standard list view threshold applies to all users except local server administrators, who are not bound by either threshold. If you set the query throttle mode to Override, users who have the required permissions in the Web application user policy can query at the higher “auditors and administrators” threshold. Local server administrators remain unbound by either threshold. Finally, if you set the query throttle mode to Strict, this closes down the local server administrator loophole and the standard list view threshold applies to all users.

Hope this Help

Thanks

Happy SharePointing ūüėČ

 

CheckIn and Approve all pages(PowerShell) SharePoint

Hello Folks,

After long time i am writing this blog.  here we gonna talk about checkin and publish all pages at once.

there are lots of ways to check in and approve pages at once. like from Site structure and powershell or you can check in and approve pages one by one from page library. but if you have 100s of  subsites in site collection so those method can be headache and painful for you.  so this script can help you out to checkin and approve all pages from your site collection even you have thousands of subsites in site collection.

 

function PublishAllPages ($url)

{

    $site = Get-SPSite -Identity $url

    #Walk through each Publishing Web and check in every page

    $site | Get-SPWeb -limit all | ForEach-Object {

        #Check to see if site is a publishing site

        if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($_)) {

            write-host "Reviewing pages in"$_.Title"site...."

            #Get the Publishing Web and pages within it

            $publishingWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($_)

            $publishingPages = $publishingWeb.GetPublishingPages()

            foreach ($publishingPage in $publishingPages)

            {

                #Check to ensure the page is checked out, and if so, check it in

                if ($publishingPage.ListItem.File.CheckOutStatus -ne "None")

                {

                    CheckInPage -page $publishingPage -web $_

                }

                else

                {

                    #Notify administrator that the page is already checked in

                    write-host $publishingPage.Title"("$publishingPage.Name") has already been checked in"

                }

                #Check to ensure page is checked in, and is so, approve it

                if ($publishingPage.ListItem.File.CheckOutStatus -eq "None")

                {

                    ApprovePage -page $publishingPage

                }

            }

        }

        else

        {

            #Notify administrator that the site is not a publishing site

            write-host $_.Title"is not a publishing site"

        }

    }

    #Dispose of the site object

    $site.Dispose()

}

function CheckInPage ($page, $web)

{

    #Check to ensure the page is checked out by you, and if so, check it in

    if ($page.ListItem.File.CheckedOutBy.UserLogin -eq $web.CurrentUser.UserLogin)

    {

        $page.CheckIn("Page checked in automatically by PowerShell script")

        write-host $page.Title"("$page.Name") has been checked in"

    }

    else

    {

        write-host $page.Title"("$page.Name") has not been checked in as it is currently checked out to"$page.ListItem.File.CheckedOutBy

    }

}

function ApprovePage ($page)

{

    if($page.ListItem.ListItems.List.EnableModeration)

    {

        #Check to ensure page requires approval, and if so, approve it

        if ($page.ListItem["Approval Status"] -eq 0)

        {

            write-host $page.Title"("$page.Name") is already approved"

        }

        else

        {

            $page.ListItem.File.Approve("Page approved automatically by PowerShell script")

            write-host $page.Title"("$page.Name") has been approved"

        }

    }

    else

    {

        write-host $page.Title"("$page.Name") does not require approval in this site"

    }

}

after running above script run the below command to call above script.

PublishAllPages -url sitecollectionurl

Thanks to  for this script!

Hope this help.

Happy SharePointing ūüėČ

The EXECUTE permission was denied on the object proc_MSS_GetTopology’, database ‘Search_Service_Application_DB

Hello Folks,

when i got back to work in the morning i saw my search service was not working and throwing the error.

The EXECUTE permission was denied on the object ‘proc_MSS_GetTopology’, database Search_Service_Application_DB ¬†{GUID} ‚ÄĚ ¬†this was caused due to the fact my new farm account didn‚Äôt have the‚ÄúSPSearchDBAdmin‚ÄĚ ¬†role assigned under the Security > Users ¬†> ‚ÄúSP farm Account‚ÄĚ ¬†on Search_Service_Application_DB¬† database (SQL Server Management Studio) other databases related to SharePoint Search service.¬† Once this was resolved my ‚ÄúSearch Service Application: Search Administration‚ÄĚ page displayed and I could create crawls. ¬†you can follow below image for assigning the role of¬†SPSearchDBAdmin.

423350

 

Thanks

Hope this Help.

Happy SharePointing ūüôā

 

 

Search Application Topology

hey folks,

just recently i have implemented Search topology  with PowerShell so i thought i should share with you. there is no more UI options to set the search topology on different servers as we used to do in SharePoint2010, in SharePoint2013 you have to do it with PowerShell cmdlet , my current  scenario is that i have 3 servers and i have divided all component on these servers as you can see in the picture of After movement.

1 App Server

2 Web Front-end Servers.

SharePoint farm environment usually the Application Server will host all the Services including the Search Application services. The Search Application consists of several Search components like

  • Admin
  • Crawler
  • Content Processing
  • Analytics processing
  • Query Processing
  • Index

   Before Movement

Untitled

   After Movement 

search topology

 

below is the PowerShell cmdlet through these commands you can move the search Component.


$ssa = Get-SPEnterpriseSearchServiceApplication
$active = Get-SPEnterpriseSearchTopology -SearchApplication $ssa -Active
$clone = New-SPEnterpriseSearchTopology -SearchApplication $ssa -Clone ‚ÄďSearchTopology $active

$Srv2 = Get-SPEnterpriseSearchServiceInstance -Identity "Server Name Here"
New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $clone -SearchServiceInstance $Srv2
New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology $clone -SearchServiceInstance $Srv2
New-SPEnterpriseSearchContentProcessingComponent -SearchTopology $clone -SearchServiceInstance $Srv2
New-SPEnterpriseSearchCrawlComponent -SearchTopology $clone -SearchServiceInstance $Srv2

Start-SPEnterpriseSearchServiceInstance -Identity $Srv2
Set-SPEnterpriseSearchTopology -Identity $clone
‚ÄĒ‚ÄĒ‚ÄĒ‚ÄĒ‚ÄĒ-
<em>Clone again to remove original</em>

$ssa = Get-SPEnterpriseSearchServiceApplication
$active = Get-SPEnterpriseSearchTopology -SearchApplication $ssa -Active
$clone = New-SPEnterpriseSearchTopology -SearchApplication $ssa -Clone ‚ÄďSearchTopology $active

Get-SPEnterpriseSearchComponent -SearchTopology $clone¬† ‚ÄĒ to get the component id for the subsequent commands

Remove-SPEnterpriseSearchComponent -Identity  <strong><span style="text-decoration: underline;">COMPID</span></strong> -SearchTopology $clone -confirm:$false
Set-SPEnterpriseSearchTopology -Identity $clone

‚ÄĒ‚Äď

COMPID is the component id of the search component to be removed. You can get all component running on the server by using the command

Get-SPEnterpriseSearchComponent -SearchTopology $clone

 

thanks

Hope this help

Happy sharePointing ūüėČ

 

SharePoinT 2013 Work Management Service : ERROR –> SORRY, WE‚ÄôRE HAVING TROUBLE REFRESHING YOUR TASKS. CONTACT YOUR ADMINISTRATOR IF YOU CONTINUE TO HAVE PROBLEMS

Hey Folks,

Problem 

i was working on work management service / Task management suddenly user came to me and asked some help regarding task syncing problem. User created a task and assign to another user ¬†but task was not showing in MyTask section in UserProfile ¬†and it was throwing error¬†“Sorry, we‚Äôre having trouble refreshing your tasks. Contact your administrator if you continue to have problems”.

 

012714_0720_sharepoint21

 

Solution :  need to check all these points

  • Does a Work Management Service Application exist?
    You can check this if you open the SharePoint 2013 Management Shell and type, this will show you list of Services
 
 Get-SPServiceApplication.  
  • If it does not exist, you have to create one. This can be done via Central Administration or Poweshell.
  • Set the Service Application Pool in a variable.
$SvcAppPool= Get-SPServiceApplicationPool "SvcAppPool"
  • Create the Service Application and assign it to the Application Pool.
 $SvcApp = New-SPWorkManagementServiceApplication -ApplicationPool $SvcAppPool -Name  "WorkManagementServiceApplication"
  • ¬† ¬† ¬†¬†Verify the Service Application.
 
Get-SPServiceApplication | Select Name
  • Now is the Work Management Service running. Check this in the Central Administration -> Manage Services on Server
  • Does an User Profile Service Application exist and is it running?
  • Has the service account under which the Work Management Service is running Full Control permissions to the User Profile Service Application? (Central Administration -> Manage Services and ¬†mark the User Profile Service Application¬†√†¬†click on Permissions in the Ribbon¬†√†¬†grant the service account Full Control).
  • you can check ¬†which service account running the app pool using PowerShell. This script will show you Service account.
$sa = Get-SPServiceApplication | where {$_.DisplayName ‚Äďmatch "WorkManagementServiceApplication"}¬†
$sa.ApplicationPool

after these steps IISRESET and check your Profile Task Section MyTask.

I Hope this Help you.

Happy SharePointing ūüėČ

 

Enable notifications for Tasks list in SharePoint 2013

Hi SharePoint Folks,

In SharePoint 2013 you will find that the option to enable email notification for Tasks list is no longer there. It used to be under List Settings > Advanced Settings > Send e-mail when ownership is assigned? (Yes/No). It is still there for Issues list in SharePoint 2013 however. now you need to enable email notification from Power Shell through this script.

Add-PSSnapin Microsoft.SharePoint.Powershell
 
$web = Get-SPWeb "http://myServer/myWeb"
$list = $web.Lists.TryGetList("Tasks")
 
$list.EnableAssignToEmail = $true
$list.Update()

Once email notification is enabled for the Tasks then create new task and assign to any user. after that user will receive the email regarding new task which assigned to him or her.

Note: Before you run this code, make sure that you have configured outgoing mail.

Happy SharePointing ūüėČ

Administration Content Database in Suspect Mode

 

Go to your SQL Server and ensure either your Central Admin Content Database or Config Database, if it is in Suspect mode,  see snapshot below:

1

 

Central Admin Content database or a Config database can abruptly go into the suspect mode without any apparent logical reason. In my case, SharePoint Central Admin Content Database went into the Suspect mode.

To resolve the issue, follow steps in the following order as mentioned:

Go to your MSSQLData files that reside under: C:Program FilesMicrosoft SQL ServerMSSQL10.MSSQLSERVERMSSQLDATA

 

2

 

. Identify your Central Admin Content Database name in my case it got screwed up and was in the suspect: mode: so this is my content database name SharePoint_AdminContent_38c5cc2d-aeec-4dc2-b7a5-65457250ae2c

Please take a backup of the corrupted .mdf and .ldf files, before following other steps.

 

Open your SQL Server Management Studio ->, New Query and it opens up your SQL Query editor, copy and paste the query below and change the highlighted to your database name:

Use master

–Verify whether Database has any issues
EXEC sp_resetstatus “SharePoint_AdminContent_38c5cc2d-aeec-4dc2-b7a5-65457250ae2c.mdf”

—Alter database and put it on Emergency Mode
ALTER DATABASE “SharePoint_AdminContent_38c5cc2d-aeec-4dc2-b7a5-65457250ae2c” SET EMERGENCY
DBCC checkdb(‘SharePoint_AdminContent_38c5cc2d-aeec-4dc2-b7a5-65457250ae2c’)

–Set the database in the Single User mode
ALTER DATABASE “SharePoint_AdminContent_38c5cc2d-aeec-4dc2-b7a5-65457250ae2c” SET SINGLE_USER WITH ROLLBACK IMMEDIATE

–Repair the database and allow data loss
DBCC CheckDB(‘SharePoint_AdminContent_38c5cc2d-aeec-4dc2-b7a5-65457250ae2c’,REPAIR_ALLOW_DATA_LOSS)

–Set the database back to Multi-User mode
ALTER DATABASE “SharePoint_AdminContent_38c5cc2d-aeec-4dc2-b7a5-65457250ae2c” SET MULTI_USER

–Ensure Database is reset
EXEC sp_resetstatus ‘SharePoint_AdminContent_38c5cc2d-aeec-4dc2-b7a5-65457250ae2c’

 

Execute all the commands in your SQL Query Editor and there you go, Go back to your SQL Management Studio and you can see that the (Suspect) mode issue against the Content/Config database is fixed and the database got fully repaired and restored.

To verify , hit your Central Administration and it starts working just fine…

 

Happy SharePointing ūüėČ

Crazy Distributed Cache (AppFabrikCache) SharePoint Server 2013

SharePoint geeks,

well i can not tell you how many time i have repaired this service and¬†it takes my patience exam in every end of week. And i have done many battles with this service. i still couldn’t find the reason¬†why it stop often, if anyone knows that Please let me know. so i thought ¬†should share my experience with other geeks. ¬†just few steps to repair this service.

What Is Distributed Cache Service?

Distributed Cache Service is a customized version of Windows App Fabric deployed in SharePoint 2013.
The Distributed Cache service provides caching functionality to features in SharePoint Server 2013. The Distributed Cache service is either required by or improves performance of the following features:

  • Authentication
  • Newsfeeds
  • OneNote client access
  • Security Trimming
  • Page load performance

There is no GUI for AppFabric so make sure  following 10 named cache containers should be there through this cmd.

Run SharePoint Management Shell and use below cmd this command should return the list of these containers.

  • ¬†Get-Cahce
  1. DistributedDefaultCache
  2. DistributedAccessCache
  3. DistributedActivityFeedCache
  4. DistributedBouncerCache
  5. DistributedLogonTokenCache
  6. DistributedServerToAppServerAccessTokenCache
  7. DistributedSearchCache
  8. DistributedSecurityTrimmingCache
  9. DistributedActivityFeedLMTCache
  10. DistributedViewStateCache

Allocate Memory on Distributed Cache Service

When SharePoint Server 2013 is installed, 10% of the total physical memory is allocated. The Distributed Cache service use 50% of this memory as storage and the other to manage the memory.

This cache size can be increased when:

  • You add more memory on the Server
    • Be aware, ¬†when you add memory to the server, the Distributed Cache isn’t updating by himself. You need to reconfigure the Cache Size.
  • If you have a dedicated caching server
    • You should calculate it so¬†:
  • Determine the total sum of physical memory. Let‚Äôs take the example that your server has 16GB of memory.
  • You have to book 2 GB of memory for other processes. So this means 16GB ‚Äď 2GB = 14GB

Now we have to take the half of this amount and that size is our AppFabric Cache Size : 14GB / 2 = 7GB

Change the Memory allocation

Use this procedure to reconfigure the memory allocation of Cache Size

Use-CacheCluster
Get-APCacheHostConfiguration ‚ÄďComputerName ‚ÄďCachePort ¬†22233

you can also update from Central Administration

Graceful shutdown of the Distributed Cache Service

use SharePoint Management Shell to run these commands

  • Stop-SPDistributedCacheServiceInstance ‚Äď Graceful
  • Remove-SPDistributedCacheServiceInstance

make sure your Distributed Cache service using Farm Account  if not so you first need to change its service account. below are the commands through which you can change Distributed Cache service account.

  • $farm = Get-SPFarm
  • $cacheService = $farm.Services | where {$_.Name ‚Äďeq “AppFabricCachingService”}
  • $account = Get-SPManagedAccount ‚ÄďIdentity ¬†domainnameUSER_NAME
  • $cacheService.ProcessIdentity.CurrentIdentityType = “USER”
  • $cacheService.ProcessIdentity.ManagedAccount = $account
  • $cacheService.ProcessIdentity.Update()
  • $CacheService.ProcessIdentity.Deploy()

Add new Service Instance 

Add-SPDistributedCacheServiceInstance
Restart-CacheCluster

after restart Cahce Cluster just run IISRESET cmd.

That’s it you done.

Happy SharePointing ūüėČ