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

Tuesday, July 28, 2020

Orphaned features in SharePoint Farm

Leave a Comment
While working for a client project and deploying existing SharePoint solution face issue about orphaned features which gives error a feature with feature id XXXXX already exist in farm.

There are two solution either in feature set force install option or delete orphaned features using following powershell commands:

Get-SPFeature | ? {$_.Scope -eq $null}


$feature = Get-SPFeature | ? {$_.DisplayName -eq "FeatureToBeDeleted"}

$feature.Delete()


Read More

Wednesday, June 3, 2020

PowerShell: Migrate SharePoint list content from one farm to other farm using CSOM

Leave a Comment
Scenario:
I met a scenario, where I need to migrate some list items (around 500+) from one farm (development) to another farm (Staging) and then to Production farm.

Ideal scenario probably would be to create list schema with content. However, in my current scenario I used CSOM for copying list items. Also in my scenario I just can't replace current content of destinate list item. I must have to just copy/move list items which are required for newly developed components.

Solution:

First I save list as list template along with content from source farm and create new list in destination farm using saved & imported list template definition. Then I delete list items which is not supposed to be copied. Although this can be skipped or cater through power shell script. However, due to quick delivery I wrote following power shell script which serve my purpose.

#Since I am doing for On-Premises, so I must have to import Client runtime for On-Premises
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Here I am getting user credentials
$siteURL="http://SomeSiteUrl/"
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)
$pwd=Read-Host -Prompt "Enter password" -AsSecureString
$creds=New-Object System.Net.NetworkCredential("domain\UserName",$pwd)
$ctx.Credentials=$creds

$sourceList=$ctx.Web.Lists.GetByTitle("[{ImportedListFromDestinationFarm}]")
$destList=$ctx.Web.Lists.GetByTitle("[{SourceListWhereDataNeedToCopied}]")
$sourceListItems=$sourceList.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
$fields=$sourceList.Fields
$ctx.Load($sourceListItems)
$ctx.Load($sourceList)
$ctx.Load($destList)
$ctx.Load($fields)
$ctx.ExecuteQuery() 

#Here I am making sure, fields of list item isn't hiddent, or not readonly & don't have attachment
#and then updating in destination list
foreach($item in $sourceListItems)
 {
 #Write-Host $item.ID
$listItemInfo=New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$destItem=$destList.AddItem($listItemInfo)
foreach($field in $fields)
{
#Write-Host $field.InternalName "-" $field.ReadOnlyField
if((-Not($field.ReadOnlyField)) -and (-Not($field.Hidden)) -and ($field.InternalName -ne "Attachments") -and ($field.InternalName -ne "ContentType"))
{
#Write-Host $field.InternalName "-" $item[$field.InternalName]
$destItem[$field.InternalName]=$item[$field.InternalName]
$destItem.update()
} }}
$ctx.ExecuteQuery()
Read More

Sunday, August 25, 2019

Configure Gmail as SMTP for SharePoint 2016 server to relay messages

Leave a Comment
This blog post is about configuring gmail as smtp for SharePoint 2013/2016/2019 to relay email messages on behalf of SharePoint.

First of all we need to configure SMTP server on Windows server (Currently I am using Windows Server 2016 Standard)

If IIS Manager 6 feature/role isn't setup first we need to set it up from Add server roles & features.

Once configured, open IIS 6 Manager and right click on SMTP Virtual server and click properties:

Until we want SMTP server to use specific IP address, leave the setting as it is in General tab
Then click Access tab
Make sure by clicking Authentication button that anonymous access is selected
On Access tab click on connection button and select second option or choose first option with your server IP address added, then click OK.
On Access tab click on Relay and choose All except list below option as shown below
Then click on delivery tab, and choose Outbound security button and select Basic authentication and enter gmail credentials and check TLS encryption and click OK.
In the Outbound connection, enter 587 as TCP Port and click OK.
In the delivery tab click Advanced button and fully qualified domain name FQDN and smart host as smtp.gmail.com
Then login to gmail account which we are using as SMTP relay, click on My Account and then Sign in security  and select Allow less secure apps to ON position

Don't forget to update POP UP setting of gmail account

Although gmail SMTP as relay has been completed and can be verified by using a simple Powershell command/script as below:

Just to explain, here from address can be used as any address but email will always be come from your gmail smtp relay email address we used above.

In order to complete SharePoint outgoing email, in Centeral Admin of SharePoint, click System Settings and Outgoing email settings



Read More

Wednesday, August 7, 2019

SharePoint: How to verify current logged in user belong to which SharePoint Group

Leave a Comment
There was a scenario, we during our development cycle faced multiple time that we need to verify currently logged in user in SharePoint for its role or SharePoint Group. As based on role we have different business rules & business process automation. So following is server side code for verifying currently logged in user (either Active directory based or form based authtentication) belong to which SharePoint Group:

//Let user be authenticated first into SharePoint
SPClaimsUtility.AuthenticateFormsUser(
                       new Uri(SPContext.Current.Web.Url), username, password);                   
                       
                        SPUser spUser = SPContext.Current.Site.RootWeb.EnsureUser(SPContext.Current.Web.CurrentUser.LoginName);

                        //check logged in user belong to which SharePoint group/role
                        SPSecurity.RunWithElevatedPrivileges(delegate ()
                        {

                            //SPSite site = SPContext.Current.Site;
                            using (SPSite site = new SPSite(SPContext.Current.Web.Url))
                            {
                                using (SPWeb web = site.OpenWeb())
                                {                                   
                                    if(spUser!=null)
                                    {
                                        var userGroups = spUser.Groups;
                                        foreach (SPGroup group in userGroups)
                                        {
                                            if (group.Name.ToLower().Equals("role1"))
                                            {
                                                userGroup = "role1";
                                            }
                                            else if (group.Name.ToLower().Equals("role2"))
                                            {
                                                userGroup = "role2";
                                            }
                                            else if (group.Name.ToLower().Equals("role3"))
                                            {
                                                userGroup = "role3";
                                            }
                                        }
                                    }                                 
                                }
                            }
                        });
Read More

Monday, July 15, 2019

Which application pool id link with which worker process (w3wp.exe)

Leave a Comment
Often there are times when we need to debug our application by Debug-> attach to process option in visual studio. Here we need to figure out which application pool is currently linked with our application. So to figure out run following command:

C:\Windows\System32\inetsrv>appcmd list wp


Read More

Tuesday, June 11, 2019

How to enable Anonymous access for SharePoint 2010/2013/2016/2019 sites

Leave a Comment
In this post I will share my experience for making a SharePoint 2016 web application/site anonymous. The procedure is very much the same which we used to have for SharePoint 2010/2013 web application and exactly same approach need to be taken for SharePoint 2019 application.

Extending web application:

Well it depends on methodology and practices, but I used to extend current web application and apply anonymous access for extended application and used default site for admin purposes only. So following steps are needed to make a site anonymous.

Step 1:
As mentioned above we need to extend our current web application (if required). If extending of application isn't require, Step 1 can be skipped.



Step 2:
Select application and click on authentication provider and select zone which you need to make site anonymous. I choose internet zone as shown below




Step 3:
In Authentication provider, we checked "Enable Anonymous access" setting. Other setting can be chosen as per need example for crawling related to search NTLM based setting or kerberos or Role based authentication & authorization etc



Step 4:
Then click on web application and choose Anonymous policy. Here we can define authorization restriction based on specified zone (if we want it to assigned to user). For my case and for internet zone I choose No Policy


Step 5:
Then we need to go to extended site (if created) or sharepoint site and go to site settings & Site permissions. In my case I have variations enable, so I need to go to top level site settings under site collection administrator, as by default in variation site, site will redirect to root level variation. If you need to understand how variation or multilingual site creation work then it is in my another blogpost.

Under top level site settings under Users & Permissions section click on Site Permission and then choose anonymous access


This is all settings which is required for making a site anonymous and once visiting this site it serve as anonymous.





Read More