Wednesday, March 07, 2018

How to link your Aadhaar with Mobile Number (specially for NRIs)

I have used it for my Airtel mobile number.

Below are the steps:

1. Call the number +91-9910099100 (Toll free) from the sim that need to be linked to Aadhaar.

2. Provide the details (Aadhaar number)  and  It will send the OTP number as SMS, this OTP will be valid for next 30 mins. For me I didn't receive SMS for 30 min and at the last moment I got OTP in my email id associated with the mobile number.

3. Provide the OTP number and it will ask for confirmation. The process is done. Sms and email confirmation will be sent in few minutes.

The process is so simple.

Tuesday, December 12, 2017

Whats New in SharePoint 2016

With the evolution of Apps in SharePoint 2013, SharePoint has been improved with new features to handle both on-premises and online model.
SharePoint 2016 has few features to handle pitfalls of SharePoint 2013 and enhance the power of SharePoint.
Following new features has come up:

1. Hybrid: Unlikely with SharePoint 2013 in SharePoint 2016, business can use both cloud and On-premises to keep the data. The new feature is used to consolidated both places data in a single list. The hybrid model is simple and automated:


2. Cloud Hybrid Search: This great feature is a boon for search functionality. Now crawlers can consolidate both - cloud and on premises content to make a unified search result for O365 sites.



3. Compliance Feature: The new feature in SharePoint 2016 comes up with your own data deletion and retention policies to control the flow of data exposed to the cloud.

You can delete data in users after certain period of times.
You can preserve certain documents, emails and other files.


4. Image and video previews : In SharePoint Server 2016 when you post images and videos to a document library, you can see a preview by hovering the mouse over the image or video, or by clicking on them.

5. Information Rights Management: Office365 provides the IRM capabilities which encrypt data to make it secure.
For example, you can allow recipients to edit and print, but restrict them from forwarding to others. This policy is attached to the document.

6. Large file support: The new SharePoint 2016 supports upload/download of large files than 2046 MB which was supported in older version. Now the desired file size limit can be configured on web application level. It could be up to 10 GB.

7. Security and Privacy: In new SharePoint 2016, this is supporting new Trasport Layer Protocol (TLS 1.2) by which data is private and encrypted. This new SMTP is making data more secure.

8. Mobile Experience: SharePoint 2016 has excellent design and navigation and has more user friendly mobile view. This has a new feature, user can switch the mobile view to PC view and it is touch enabled feature. Now anyone can access SharePoint from anywhere PC or mobile and can interact with the team.

9. Open Document Format (ODF) available for document libraries: You can set an Open Document Format (ODF) file as the default file template for a document library. This way user can edit the new file with the program they choose.
Note: You need Full Control permission to set up a template for a document library. You need Full Control permission for the site to set up site content types.

10. MinRole farm topology and Server Roles: With the release of SharePoint 2016, it came with the new server role configuration feature, this feature allows a SharePoint administrator to assign the role of their choice to a specific SharePoint 2016 server. It enables the only the required functionalities and it'll make sure that all servers that belong to each role are compliant. You can also convert servers to perform the new roles when needed.


Servers in Farm



You can even look at the services running on the SharePoint 2016 server and see if they are compliant as well.


11. Reduced Downtime: Another exciting feature to manage the SharePoint servers, the size and number of the packages are immensely reduced. They’ve also removed the downtime previously required to update SharePoint servers.

12. Faster Site and Site Collection Creation: SharePoint 2013 used to take over 40 seconds to create a site. This new feature provides templates that work at same level as SQL Server, which reduces the round trips required between the SharePoint and SQL servers.
With PowerShell configurations, you can now use the SPSiteMasterMicrosoft PowerShell cmdlets to create sites and site collections quickly, generally improving site performance.

13. Removed 5,000 View Threshold (Not technically):

A Document Library can have 30,000,000 documents, that’s never been an issue. However, 5,000 seems to be the actual limit for many end users that don't know they had to index their columns.
The 5,000 view threshold is actually necessary, or your entire SharePoint would be slowed down. It prevents SQL from locking the entire database, really.
Instead of removing this unpopular threshold, they automated the creation of Indexed Columns. This means that, technically, the limit is still there, but you won’t have to worry about it.


14. App Launcher and Sites in One Place: SharePoint 2016 allows you to view both On-Premises and Office 365 in one location via the App Launcher under the “Sites” app.
The App Launcher provides easy access to Office 365 apps such as OneDrive, OneNote, and more.



15. Durable Links: The links you sent to people will remain intact even after a document moves to another location or is renamed.
You can achieve this by using a Resource-ID-based URLs for documents hosted in SharePoint. You no longer have to search files by name and can just use the resource ID containing the document stored in the database.




Following few changes has been made in SharePoint 2016:

1. Central Administration: Central Administration is not provisioned in all the servers of the farm by default now, it is only provisioned in the first server on the Farm. We can provision it in another individual server using PowerShell commands:

Microsoft PowerShell cmdlets: (Services on Server page on Central Administration > System Settings)
New-SPCentralAdministration
Remove-SPCentralAdministration

Features No Longer Available:

Product Catalog Site Template is gone, though you can still use the Catalog Feature.



I tried to add the points and features I am aware, please comment me if you know any more. I will be happy to add the unknown features.

Via[https://technet.microsoft.com][https://en.share-gate.com]

Monday, May 08, 2017

Powershell automation script to create SharePoint 2013 sites

This script picks the required data from a list "New Site Requests" which is filled by user who wants to create the site. This powershell can be used as a job to run automatically with certain interval.

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

$sourceWebURL = "http://sharepoint.site.com/support"
$sourceListName = "New Site Requests"

$SendErrorNoticeToEmailID = "abc@orgsite.com;xyz@orgsite.com;pqr@orgsite.com"
$server =  "AppContent2013_SharePointSQL" ##Config DB Server
$database = "prod_sharepoint_Content" ##Config DB name

$DatePostFix = Get-Date -format "MM-dd-yyyy_hh-mm-ss"
$LogFileName = "C:\sharepointsite\NewSiteCreation\NewLogs\SiteCreationLog_" + $DatePostFix + ".csv"

$Site_Title = ""
$Site_Description = ""
$Site_URL = ""
$Template_Type = ""
$Template_Name = ""
$Primary_Administrator = ""
$Secondary_Administrator = ""
$Quota = ""
$language=""
$Site_Type = ""
$Site_UnitDept = ""
$Site_OwnCountry = ""
$Site_BusinessImpact = ""
$Site_Expirydate = ""
$Site_HasConfidentialInfo = ""
$Site_IPPProtected = ""
$Site_LegalData = ""
$Site_FuncArea = ""
$Site_isEPDP = ""
$global:URLsinError = ""
$global:dbName = ""
$global:dbAllowSitesCount = 0
$scriptError = $false
$URLsAlreadyinUse = $true

# Read List items
function GetListItemsforSiteCreation()
{
    try {
  $spSourceWeb = Get-SPWeb $sourceWebURL
  $spSourceList = $spSourceWeb.Lists[$sourceListName]
  
  $spQuery = New-Object Microsoft.SharePoint.SPQuery
                                        $camlQuery = "" +
                                                              "" +
                                                                "" +
                                                                        "" +
                                                                        "New" +
                                                                "
"+                                                                "" +
                                                                    "" +
                                                                        "" +
                                                                        "Approve Non-Encrypted" +
                                                                    "
" +                                                                                                                                         "" +
                                                                        "" +
                                                                        "Approve Encrypted" +
                                                                    "
"+                                                                                                                                   "
" +                                                                                                                              "
" +                                                            "
"
  $spQuery.Query = $camlQuery
  $spSourceItems = $spSourceList.GetItems($spQuery)
  
  $UrlsInUse = ""

  foreach ($listItem in $spSourceItems)
  {
                            try
                            {
                               $SURL = $listItem['Full URL']

                               $URLsAlreadyinUse = (Get-SPWeb $SURL -ErrorAction SilentlyContinue ) -ne $null 
                                if ($URLsAlreadyinUse)
                                {
                                    $URLsAlreadyinUseMsg = "Site ("+$listItem["Full URL"] +")  Already Exists. Item Status changed accordingly, skipping to next item.URL"  

                                    $listItem["Status"] = "Site Already Exists";
                                    $listItem.Update();

                                    "{0},{1}" -f $listItem['Full URL'], $URLsAlreadyinUseMsg |Add-Content $LogFileName

                                    $UrlsInUse = $UrlsInUse + $listItem["Full URL"] + "; "; 
                                    
                                    continue;
                                }    
                                
                                CreateSite $listItem $spSourceWeb
                            }
                            Catch [exception]
                            { 
                                # Logging the exception in log file
                                "{0},{1}" -f $listItem['Full URL'], $_.Exception.Message |Add-Content $LogFileName   
                                    $scriptError = $true   
                                 
                            }
    
}

  # List Item For Loop finished

  try 
  {
    #Send email
            $date  = Get-Date
$subject = ""
$body = ""
            
            if((-not [system.string]::IsNullOrEmpty($UrlsInUse)) -and (-not [system.string]::IsNullOrEmpty($global:URLsinError)))
            {
                $subject = "Site creation Job notification - $date Site(s) already exists & few Site(s) returned error on creation"
$body = "Following site(s) already exists :`r`n $UrlsInUse `r`n`n Following site(s) returned error on creation :`r`n $global:URLsinError"
                
                SendMail $spSourceWeb $SendErrorNoticeToEmailID $subject $body
                $scriptError = $true
            }
            elseif (-not [system.string]::IsNullOrEmpty($UrlsInUse))
            {
$subject = "Site creation Job notification - $date Site(s) already exists"
$body = "Following site(s) already exists :`r`n $UrlsInUse"

                SendMail $spSourceWeb $SendErrorNoticeToEmailID $subject $body
                $scriptError = $true   

            }                      
            elseif (-not [system.string]::IsNullOrEmpty($global:URLsinError))
            {
   $subject = "Site creation Job notification - $date : Site(s) returned error on creation"
   $body = "Following site(s) returned error on creation :`r`n $global:URLsinError"

                SendMail $spSourceWeb $SendErrorNoticeToEmailID $subject $body 
                $scriptError = $true
            }
            

        if (($URLsAlreadyinUse -ne $true) -and ($scriptError -ne $true))
        {
$subject = "Site creation Job notification - $date : Site(s) is(are) created successfully"
$body = "Site(s) is(are) created successfully"
            SendMail $spSourceWeb $SendErrorNoticeToEmailID  $subject $body
        }             
    
    }
                            Catch [exception]
                            { 
                                # Logging the exception in log file
                                "{0},{1}" -f $global:URLsinError, "Error while sending mail--" + $_.Exception.Message |Add-Content $LogFileName   
                                    $scriptError = $true   
                                 
                            }
    }
    Catch [exception]
    { 
                 # Logging the exception in log file
                "{0},{1}" -f $global:URLsinError, "Error in method ( GetListItemsforSiteCreation() )--" + $_.Exception.Message |Add-Content $LogFileName   
                    $scriptError = $true   
                                 
    }
}


function CreateSite($listItem, $web)
{

$Site_Title = ""
$Site_Description = ""
$Site_URL = ""
$Template_Type = ""
$Template_Name = ""
$Primary_Administrator = ""
$Secondary_Administrator = ""
$Quota = ""
$language=""
$Site_Type = ""
$Site_UnitDept = ""
$Site_OwnCountry = ""
$Site_BusinessImpact = ""
$Site_Expirydate = ""
$Site_HasConfidentialInfo = ""
$Site_IPPProtected = ""
$Site_LegalData = ""
$Site_FuncArea = ""
$Site_isEPDP = ""

   $scriptError = $false
  if ([string]$listItem["Site Title"] -ne $null) {
   $Site_Title = $listItem["Site Title"]
  }

    if ([string]$listItem["Site Description"] -ne $null) {
        $Site_Description = $listItem["Site Description"]
    }

    if ([string]$listItem['Full URL'] -ne $null) {
        $Site_URL = $listItem['Full URL']
    }

    if (($listItem["sharepointsite Standard template"] | Out-String) -ne $null) {
                    if ([System.Convert]::ToBoolean($listItem["sharepointsite Standard template"]) -eq $true) {
                        $Template_Type = "Standard" }

                    else {
                        $Template_Type = "User Defined" } }

    if ([string]$listItem["Site Type"] -ne $null) {
                    if ([string]$listItem["Site Type"] -eq "Teams") {
                        $Template_Name = "Team Site" }
                    elseif ([string]$listItem["Site Type"] -eq "Projects") {
                        $Template_Name = "Project Site" }
                    elseif ([string]$listItem["Site Type"] -eq  "Community") {
                        $Template_Name = "Community Site" }
                    elseif ([string]$listItem["Site Type"] -eq  "Wiki") {
                        $Template_Name = "Enterprise Wiki" }
                    #elseif ([string]$listItem["Site Type"] -eq  "Blogs") {
                        #$Template_Name = "Blog"; }
                    else {
                        $Template_Name = "" }
    }

    if (-not [system.string]::IsNullOrEmpty($listItem["Primary Owner"])) {
                            
                            $Primary = New-Object Microsoft.SharePoint.SPFieldUserValue($web, [system.string]$listItem["Primary Owner"])
                             $Primary_Administrator = $Primary.User.UserLogin
                    }
                    if (-not [system.string]::IsNullOrEmpty($listItem["Secondary Owner"])) {
                            
                            $Secondary = New-Object Microsoft.SharePoint.SPFieldUserValue($web, [system.string]$listItem["Secondary Owner"]) 
                             $Secondary_Administrator = $Secondary.User.UserLogin
                    }
                
    if ([system.string]$listItem["Site Quota"] -ne $null) {
                    $Quota = [system.string]$listItem["Site Quota"];
                    }

    if ([system.string]$listItem["LCID"] -ne $null) {
                    $language = if([system.string]$listItem["LCID"] -eq "") { [system.string]$listItem["LCID"] } else { "1033" }
                    }
                else {
                    $language = "1033" }

                if ([system.string]$listItem["Site Type"] -ne $null)
                {
                    $Site_Type = [system.string]$listItem["Site Type"];
                    if ([system.string]$listItem["Site Type"] -eq "Teams") {
                        $Site_Type = "Team" }
                    elseif ([system.string]$listItem["Site Type"] -eq "Projects") { 
                        $Site_Type = "Project"
                        }
                    elseif ([system.string]$listItem["Site Type"] -eq "Blogs") {
                        $Site_Type = "Blog"
                        }
                }    

    if (([system.string]$listItem["Owning Unit"] -ne $null) -and ([system.string]$listItem["Owning Department"] -ne $null)) {
                    $Site_UnitDept = [system.string]$listItem["Owning Unit"] + "." + [system.string]$listItem["Owning Department"] }

                if ([system.string]$listItem["Country"] -ne $null) {
                    if ([system.string]$listItem["Country"] -ne "Other") {
                        $Site_OwnCountry = [system.string]$listItem["Country"] }
                    elseif ([system.string]$listItem["Other Country"] -ne $null) {
                        $Site_OwnCountry = [system.string]$listItem["Other Country"] }

                if ([system.string]$listItem["Business Impact"] -ne $null) {
                    $Site_BusinessImpact = [system.string]$listItem["Business Impact"] }
                else {
                    $Site_BusinessImpact = "Low" }

                if ([system.string]$listItem["Site Expiration Date"] -ne "") {
                    $Site_Expirydate = ([system.string]$listItem["Site Expiration Date"]).Substring(0, ([system.string]$listItem["Site Expiration Date"]).IndexOf(" ")) }

                if ([system.string]$listItem["Confidential Info"]-ne $null) {
                    $Site_HasConfidentialInfo = if ([System.Convert]::ToBoolean($listItem["Confidential Info"])  -eq $true) { "1" } else { "0" }
                    }
                else {
                    $Site_HasConfidentialInfo = "0" }

                if ([system.string]$listItem["IPP Protected"]-ne $null) {
                    $Site_IPPProtected = if ([System.Convert]::ToBoolean($listItem["IPP Protected"])  -eq $true) { "1" } else { "0" }
                    }
                else {
                    $Site_IPPProtected = "0"
                    }

                if ([system.string]$listItem["Is Legal Data"]-ne $null) {
                    $Site_LegalData = if ([System.Convert]::ToBoolean($listItem["Is Legal Data"])  -eq $true) { "1" } else { "0" }
                    }
                else {
                    $Site_LegalData = "0"
                    }

                if ([system.string]$listItem["Functional Area"] -ne $null) {
                    $Site_FuncArea = [system.string]$listItem["Functional Area"]
                    }
                else {
                $Site_FuncArea = "";
                }

                if ([system.string]$listItem["Site Type"] -ne $null) {
                    $Site_isEPDP = if([system.string]$listItem["Custom Site Template"]  -eq "EPDP") { "1" } else { "0"}
                    }
                else {
                    $Site_isEPDP = "0"
                    }

                if ([system.string]$listItem["EPDP Program Manager"] -ne $null) {
                    $Site_EPDPprogramManager = New-Object Microsoft.SharePoint.SPFieldUserValue($web,[system.string]$listItem["EPDP Program Manager"]).User;
                    }
                else {
                    $Site_EPDPprogramManager = $null;
                    }

                if ([system.string]$listItem["EPDP Project Phase"]-ne $null) {
                    $Site_EPDPprojectPhase = [system.string]$listItem["EPDP Project Phase"]
                    }
                else {
                    $Site_EPDPprojectPhase = ""
                    }

                if ([system.string]$listItem["EPDP Product Structure"]-ne $null) {
                    $Site_EPDPproductStructure = [system.string]$listItem["EPDP Product Structure"]
                    }
                else {
                    $Site_EPDPproductStructure = ""
                    }


    # "Setting Site Template"
    $parsedSiteTemplate = Get-SPWebTemplate | where-object {($_.Title -eq "Blank Site") -and ($_.LocaleId -eq $language)}
$parsedSiteTemplateName = $parsedSiteTemplate.Name
    

    # "Setting Quota Template"
    $Quota = $Quota.Replace(" ","")
    $Quota = "quota_$Quota"
    $contentService =[Microsoft.SharePoint.Administration.SPWebService]::ContentService
    foreach ($quotaTemplate in $contentService.QuotaTemplates | ? {$_.Name.StartsWith("$Quota")} | % {$parsedQuotaTemplate = $_}) {}
   
    
    #  "Creating site collection..."
    try {
       if ($listItem["Status"] -eq "Approve Encrypted")
       {
            # Get DB Name first time, if the selected content database has not available space for sites, access another content database 
            if (([system.string]::IsNullOrEmpty($global:dbName)) -or ($global:dbAllowSitesCount -eq 0))
            {
                GetEncryptedDBName
            }                              
                                
            if($global:dbName -ne "" -and $global:dbName -ne $null) 
            {
                $global:dbAllowSitesCount = $global:dbAllowSitesCount - 1
           New-SPSite -Url $Site_Url -Name $Site_Title -Description $Site_Description -ContentDatabase $global:dbName -OwnerAlias $Primary_Administrator -SecondaryOwnerAlias $Secondary_Administrator -QuotaTemplate $parsedQuotaTemplate -Language $language -ErrorAction Stop            
            }
      }
      else 
      {
        New-SPSite -Url $Site_Url -Name $Site_Title -Description $Site_Description -OwnerAlias $Primary_Administrator -SecondaryOwnerAlias $Secondary_Administrator -QuotaTemplate $parsedQuotaTemplate -Language $language -ErrorAction Stop
 }
    }
    catch [Exception]
    {
        $scriptError = $true
        "{0},{1}" -f $listItem['Full URL'], "`nError in creating site collection.`n" + " Exception - " + $_.Exception.Message + "`n" |Add-Content $LogFileName  
        $global:URLsinError = $global:URLsinError + $listItem['Full URL'] + "; "; 
        
   #exit
    }

  if ($scriptError -eq $false) {
    
                    if ($listItem["sharepointsite Standard template"] -ne $null) {
                                        if ($listItem["sharepointsite Standard template"] -eq $false -and $listItem["Full URL"] -ne $null)
                                        {
                                             SetGroupsForSite $Site_URL
ProvisioningCustomTemplateSites $web $listItem
                                             UpdateCustomSiteMetadata $listItem $web
                                        }

                                    $listItem["Status"] = "Completed";
                                    $listItem.Update();
                                }
                                else
                                {
                                    $scriptError = $true   
                                    "{0},{1}" -f $listItem['Full URL'], "There is some error while creating site for the URL." |Add-Content $LogFileName  
                                    $global:URLsinError = $global:URLsinError + $listItem['Full URL'] + "; "; 
                                    
                                }

            "{0},{1}" -f $listItem['Full URL'], "The site is created successfully." |Add-Content $LogFileName 

     }
     
  }
}

function SetGroupsForSite ($Site_URL)
{
    $site = Get-SPSite $Site_Url
$rootWeb = $site.RootWeb

#  "Creating default groups..."

$rootWeb.AssociatedVisitorGroup = $null
$rootWeb.Update()
$rootWeb.CreateDefaultAssociatedGroups($Primary_Administrator, $Secondary_Administrator, $Site_Title)
$rootWeb.Update()

#  "Setting access request values..."
$rootWeb.RequestAccessEmail = $site.Owner.Email
$rootWeb.Update()

Enable-SPFeature -identity "ccf46f39-b9f4-4f9b-8d11-54286c42aaaa" -URL $Site_URL
Enable-SPFeature -identity "67b14c35-627a-4e09-8a2c-d69be020bbbb" -URL $Site_URL
Enable-SPFeature -identity "23c8a91c-c553-4b97-8fe3-f53e9f73cccc" -URL $Site_URL 
}


function ProvisioningCustomTemplateSites($RequestWeb, $listItem)
 {
            ## Provisioning the Custom Template. 
            ## Blank Site is created by the script for cases where User Defined Template is selected.
            ## This method provisions User Defined Template to the blank site.
            ## It also ensures that all the features of that user defined template are activated.
            try {
            $site = $listItem['Full URL'] 
            $myNewBlankSite = Get-SPSite $site  
            $myNewBlankWeb = Get-SPWeb $site        
        
                
                $requestedTempalte = [System.String]($listItem["Custom Site Template"]);
                
                if (($requestedTempalte.Equals("Wiki")) -ne  $true)
                {
                    ##Get the WSP File
                    $TempllistItem = $RequestWeb.Lists["User Defined Site Templates"] 
                    foreach($tmp in $TempllistItem.Items)
                    {
                        if ($tmp["Title"] -eq $listItem["Custom Site Template"])
                        {
                            $tmpWspName = $tmp["Name"]
                        }
                    }
                    
                    $sourceSolutionFile = $RequestWeb.GetFile("User Defined Site Templates/" + $tmpWspName.Trim())

                    ## Get the Solution Gallery for the SPSite
                    $solutionGallery = $myNewBlankSite.GetCatalog([Microsoft.SharePoint.SPListTemplateType]::SolutionCatalog);

                    ## Add the WSP File
                    $solutionFile = $solutionGallery.RootFolder.Files.Add($sourceSolutionFile.Name, $sourceSolutionFile.OpenBinary())

                    do 
                    {
                            Start-Sleep -Seconds 5;
                            try
                            {
                                $testsolution = Get-SPUserSolution -Identity $sourceSolutionFile.Name -Site $myNewBlankSite
                            }
                            catch {  
                                 "{0},{1}" -f $listItem['Full URL'], "`nError in getting user defined solution.`n" + "Exception - " + $_.Exception.Message + "`n" |Add-Content $LogFileName                                
                             }
                    }
                    while(!$testsolution);
                    
                    ## Activate Solution    
                    Install-SPUserSolution -Identity $sourceSolutionFile.Name -Site $myNewBlankSite

                    Start-Sleep -Seconds 5;

                    ## Ensuring proper activation of all features of the Custom Template Solution- Important - Get updated site object
                    $newsite = Get-SPSite -Identity $site
           $spFeatureColl = $newsite.Features
                    foreach ($spFeature in $spFeatureColl)
                    {
                        $feature = $spFeature.Definition 
                                if(($feature.SolutionId -eq $testsolution.SolutionId) -and ($feature.Scope -eq [Microsoft.Sharepoint.SPFeatureScope]:: Site))
                                {
                                     $siteFeature = Get-SPFeature -Site $newsite.Url -Identity $feature.Id -ErrorAction SilentlyContinue
                                    if ($siteFeature -ne $null) {
                                        Enable-SPFeature -Identity $feature.Id -Url $newsite.Url

                                    }
                                }
                        
                    }
                    
                    Start-Sleep -Seconds 20;

                    #**Selecting the Custom Template for the UPDATED Site Object
                    $newsite = Get-SPSite -Identity $site
                    $templatename = $tmpWspName -replace ".wsp", ""
                    $loc = [System.Int32]::Parse(1033)
                    $webTemplate = $newsite.GetWebTemplates($loc) 
                    foreach($temp in $webTemplate | ? {$_.Title -eq $templatename.Trim()} | % {$newsite.RootWeb.ApplyWebTemplate($_.Name)})
                    {}
                                    
                }
                else
                {
                    $myNewBlankSite.RootWeb.ApplyWebTemplate("WIKI#0")                                        
                }
                    
            }
            catch [Exception]{

                "{0},{1}" -f $listItem['Full URL'], "`nError setting user template .`n" + "Exception - " + $_.Exception.Message + "`n" |Add-Content $LogFileName  
            }
        }


function UpdateCustomSiteMetadata($listItem, $web) 
        {
            try
           {
                $site = $listItem['Full URL']
                $NewCreatedSite = Get-SPSite $site              
                    $NewCreatedWeb = $NewCreatedSite.RootWeb;

                ############### Initial values - START

                $NewCreatedWeb.AllProperties["__category_key__"] = $Site_Type
                $NewCreatedWeb.AllProperties["__isEPDP_key__"] = $Site_isEPDP

                if (-not [system.string]::IsNullOrEmpty($Site_EPDPprogramManager))
                {
                $NewCreatedWeb.AllProperties["__EPDPprogramManager_key__"] = $Site_EPDPprogramManager
                }
                if (-not [system.string]::IsNullOrEmpty($Site_EPDPprojectPhase))
                {
                $NewCreatedWeb.AllProperties["__EPDPprojectPhase_key__"] = $Site_EPDPprojectPhase
                }
                if (-not [system.string]::IsNullOrEmpty($Site_EPDPproductStructure))
                {
                    $NewCreatedWeb.AllProperties["__EPDPproductStructure_key__"] = $Site_EPDPproductStructure
                }

                #$NewCreatedWeb.AllProperties["__legal_data_key__"] = $Site_LegalData

                $NewCreatedWeb.Update()

                ############### Initial Values - END

                $Site_UnitDept = ""   
                $Site_OwnCountry = ""   
                $Site_BusinessImpact = ""   
                $Site_Expirydate = ""   
                $Site_HasConfidentialInfo = ""   
                $Site_IPPProtected = "0"   
                $Site_LegalData = "0"   
                $Site_FuncArea = ""   
                $Site_isEPDP = "0"   
                $Site_EPDPprogramManager = $null;
                $Site_EPDPprojectPhase = ""   
                $Site_EPDPproductStructure = ""

                if ([String]($listItem["Owning Unit"]) -ne $null -and [String]($listItem["Owning Department"]) -ne $null) {
                  $Site_UnitDept = [String]($listItem["Owning Unit"]) + "." + [String]($listItem["Owning Department"]);
                  }
                if ([String]($listItem["Country"]) -ne $null)
                { 
                    if ([String]($listItem["Country"]) -ne "Other")
                    {
                      $Site_OwnCountry = [String]($listItem["Country"]);
                     }
                    elseif ([String]($listItem["Other Country"]) -ne $null)
                    {
                      $Site_OwnCountry = [String]($listItem["Other Country"]);
                    }
                }
                if ([String]($listItem["Business Impact"]) -ne $null) {
                  $Site_BusinessImpact = [String]($listItem["Business Impact"]); }
               else  {
                  $Site_BusinessImpact = "Low"   }
                  
                if ([String]($listItem["Site Expiration Date"]) -ne $null) {
                  $Site_Expirydate = ([system.string]$listItem["Site Expiration Date"]).Substring(0, ([system.string]$listItem["Site Expiration Date"]).IndexOf(" ")) 

                  }
                if ([String]($listItem["Confidential Info"]) -ne $null) {
                  $Site_HasConfidentialInfo = if ([System.Convert]::ToBoolean($listItem["Confidential Info"]) -eq $true) { "1" } else { "0"   }
                  
                }  else {
                  $Site_HasConfidentialInfo = "0"   
                  }
                if ([String]($listItem["IPP Protected"]) -ne $null) {
                  $Site_IPPProtected = if ([System.Convert]::ToBoolean($listItem["IPP Protected"]) -eq $true) { "1" }   else  { "0" }
                  }
                  else  {
                  $Site_IPPProtected = "0"   }
                if ([String]($listItem["Is Legal Data"]) -ne $null) {
                  $Site_LegalData = if ([System.Convert]::ToBoolean($listItem["Is Legal Data"]) -eq $true) { "1" }   else  { "0" }
                }  else {
                  $Site_LegalData = "0"   }
                if ([String]($listItem["Functional Area"]) -ne $null) {
                  $Site_FuncArea = [String]($listItem["Functional Area"]);
                }  else {
                  $Site_FuncArea = ""   }
                if ([String]($listItem["Site Type"]) -ne $null) {
                  $Site_isEPDP = if ([String]($listItem["Custom Site Template"]) -eq "EPDP") { "1" } else { "0"   }
                }  else {
                  $Site_isEPDP = "0"   }
                if ([String]($listItem["EPDP Program Manager"]) -ne $null) {
                  $Site_EPDPprogramManager = New-Object Microsoft.SharePoint.SPFieldUserValue($web, [String]($listItem["EPDP Program Manager"])).User;
                }  else {
                  $Site_EPDPprogramManager = $null; }
                if ([String]($listItem["EPDP Project Phase"]) -ne $null) {
                  $Site_EPDPprojectPhase = [String]($listItem["EPDP Project Phase"]);
                }  else {
                  $Site_EPDPprojectPhase = ""   }
                if ([String]($listItem["EPDP Product Structure"]) -ne $null) {
                  $Site_EPDPproductStructure = [String]($listItem["EPDP Product Structure"]);
                }  else {
                  $Site_EPDPproductStructure = ""   }

                

                    $NewCreatedWeb.AllProperties["__division_key__"] = $Site_UnitDept;
                    $NewCreatedWeb.AllProperties["__country_key__"] = $Site_OwnCountry;
                    $NewCreatedWeb.AllProperties["__group_key__"] = $Site_BusinessImpact;
                    $NewCreatedWeb.AllProperties["__expiry_key__"] = $Site_Expirydate;
                    $NewCreatedWeb.AllProperties["__expiry1_key__"] = $Site_Expirydate;
                    $NewCreatedWeb.AllProperties["__category3_key__"] = $Site_HasConfidentialInfo;
                    $NewCreatedWeb.AllProperties["__category4_key__"] = $Site_IPPProtected;
                    $NewCreatedWeb.AllProperties["__area_key__"] = $Site_FuncArea;
                    if ($Site_isEPDP -eq "1")
                    {
                        $NewCreatedWeb.AllProperties["__isEPDP_key__"] = $Site_isEPDP;
                        $NewCreatedWeb.AllProperties["__EPDPprogramManager_key__"] = $Site_EPDPprogramManager.Name;
                        $NewCreatedWeb.AllProperties["__EPDPprojectPhase_key__"] = $Site_EPDPprojectPhase;
                        $NewCreatedWeb.AllProperties["__EPDPproductStructure_key__"] = $Site_EPDPproductStructure;
                    }
                    if ($Site_LegalData -eq "1")
                    {
                        $NewCreatedWeb.AllProperties["__legal_data_key__"] = $Site_LegalData;
                    }
                    $NewCreatedWeb.AllProperties["__reviewedBy_key__"] = ""  

                    $NewCreatedWeb.AllProperties["__reviewedOn1_key__"] = ""   

                    $NewCreatedWeb.Update();
             }
            
            Catch [exception]
        { 
            # Logging the exception in log file
            "{0},{1}" -f $listItem['Full URL'], $_.Exception.Message |Add-Content $LogFileName    
        }
    
                               
     }


function SendMail($web, $EmailTo, $Subject, $Body)
{
            #

            #Send an email from a SharePoint Web
            #

            [Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($web, $false, $false, $EmailTo, $Subject, $Body);

}


function GetEncryptedDBName()
{     
    $connectionString = “Server=$server;Database=$database;Integrated Security=True;”
    $global:dbName = ""
    
    try 
    {
        $connection = New-Object System.Data.SqlClient.SqlConnection
        $connection.ConnectionString = $connectionString
        $connection.Open()

        $query = 
            “SELECT @@Servername, db.name, Case db.is_encrypted when '1' then 'Y' when '0' then 'N' else '0' end as Encrypted
        FROM sys.databases db
        LEFT OUTER JOIN sys.dm_database_encryption_keys dm
        ON db.database_id = dm.database_id WHERE db.is_encrypted = '1'
        ”                    
        $command = $connection.CreateCommand()
        $command.CommandText = $query

        $reader = $command.ExecuteReader();

        while($reader.read() -and ([string]::IsNullOrEmpty($global:dbName))) 
        {

            if ($reader["name"] -ne $null)
            {                                 
               try 
               {     
                                                         
                    foreach($DB in get-spcontentdatabase | ? {$_.name -eq $reader["name"]})
                    {
                        if($DB.MaximumSiteCount -gt $DB.CurrentSiteCount)
                        {
                            #DB found, create site using the $DB.name
                            $global:dbName = $DB.name
                            $global:dbAllowSitesCount = ($DB.MaximumSiteCount) - ($DB.CurrentSiteCount)

                            break;
                        }
                    } 
                }
                Catch [exception]
                {
                    # Logging the exception in log file
                    "{0},{1}" -f "Error in method: GetEncryptedDBName(). DB Name - " + $reader["name"] + ". Exception - ", $_.Exception.Message |Add-Content $LogFileName   
                }
                                                               
             }
        }
        if([string]::IsNullOrEmpty($global:dbName))
        {
            # Logging the error message in log file
            "{0},{1}" -f "Error in method: GetEncryptedDBName()", "No encrypted DB space available" |Add-Content $LogFileName              
                
        }

     }
    Catch [exception]
    {
        "{0},{1}" -f "Error in method: GetEncryptedDBName()", "SQL Can't read the Encrpted DB information" |Add-Content $LogFileName               
    }
                finally
                {
                                # Dispose the objects
                                $reader.close()
                                $connection.Close()
                }
}


GetListItemsforSiteCreation