Wednesday, June 26, 2013

Database Movement from One Web Application to another using Powershell

We may have necessity of moving databases of one web application the other.
If the databases are in bulk, then we move ahead by automating with power shell as below
Below is the script that has been written to move database from one web application the other
// DBMove.bat
cd /d %~dp0
@echo off
powershell.exe -noexit .\DBMove.ps1 .\DBMove.csv
// DBMove.csv
SourceWebAppUrl,DestinationWebAppurl
// DBMove.ps1
#-----Input parameters to the script
param($inputFile)

#------To check if Sharepoint cmdlets are registered are registered
if ((Get-PSSnapin -Name Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue) -eq $null )
{
            Add-PSSnapin Microsoft.SharePoint.Powershell 
}
#---------------------------------------------------------------------------------------------------
#-----------------------------------------Start Logging---------------------------------------------
$filepath = $MyInvocation.MyCommand.Definition                                        
$directorypath = [System.IO.Path]::GetDirectoryName($filepath)
$LogTime = Get-Date -Format yyyy-MM-dd_h-mm
$LogFile = $directorypath + "\DBMove_Log_$LogTime.txt"
Start-Transcript -Path $LogFile -Force
#---------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------
function DBMove()
{
param([string] $swebAppUrl,[string] $dwebAppUrl)

$SourceWebApp = Get-SPWebApplication -Identity $sourcewebAppUrl
$DestinationWebApp = Get-SPWebApplication -Identity $destinationwebAppUrl

if($SourceWebApp -ne $null -and  $DestinationWebApp -ne $null)
{

$SourceDBlists=Get-SPContentDatabase -WebApplication $SourceWebApp
Get-SPContentDatabase -WebApplication $SourceWebApp  | Dismount-SPContentDatabase -confirm:$false
foreach ($SourceDBlist in $SourceDBlists)
{
 Mount-SPContentDatabase $SourceDBlist.Name -DatabaseServer $SourceDBlist.Server -WebApplication $destinationwebAppUrl
}
}
else
{
  Write-Host 'Not a valid Web application url...'
}

}

#---------------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------
#loop through a csv file
Import-Csv $inputFile | ForEach{                            
    $SourcewebAppUrl = $_. SourceWebAppUrl
    $destinationAppUrl = $_.DestinationWebAppurl
              
    try
    {
  write-host "Moving Source Database from $sourcewebAppUrl to $destinationwebAppUrl...."
        SourceDBMove $sourcewebAppUrl,$destinationwebAppUrl
  write-host "Completed..."
    }
    catch
    {
  write-host "Completed with errors..."   
        Write-Output $_
    }
}
#---------------------------------------------------------------------------------------------------

#-----------------------------------------End Logging-----------------------------------------------
Stop-Transcript
#---------------------------------------------------------------------------------------------------


Portal Site Connection Url Updation using Powershell

Hi,
Generally in our site collection, we could have updated portal site name, portal site url to get the site hierarchy. We follow the below navigation to update the portal site name,url. But if there are twenty site collections where we need to update portal site name,url. At that time PowerShell script can ease the task for the same as below
//PortalSiteConnection.bat
cd /d %~dp0
@echo off
powershell.exe -noexit .\PortalSiteConnection.ps1 .\PortalSiteConnection.csv
//PortalSiteConnection.csv
MainWebAppurl
//PortalSiteConnection.ps1
#-----Input parameters to the script
param($inputFile)

#------To check if Sharepoint cmdlets are registered are registered
if ((Get-PSSnapin -Name Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue) -eq $null )
{
            Add-PSSnapin Microsoft.SharePoint.Powershell 
}
#---------------------------------------------------------------------------------------------------
#-----------------------------------------Start Logging---------------------------------------------
$filepath = $MyInvocation.MyCommand.Definition                                       
$directorypath = [System.IO.Path]::GetDirectoryName($filepath)
$LogTime = Get-Date -Format yyyy-MM-dd_h-mm
$LogFile = $directorypath + "\PortalSiteConnectionSettings_Log_$LogTime.txt"
Start-Transcript -Path $LogFile -Force
#---------------------------------------------------------------------------------------------------
#---------------------------------------------------------------------------------------------------
function PortalSiteConnectionSettings()
{
param([string] $mwebAppUrl)

$MainWebApp = Get-SPWebApplication -Identity $mainwebAppUrl

if($MainWebApp -ne $null)
{


get-spsite $($MainWebApp.Url + "*" ) -Limit ALL | ForEach-Object{if($_.PortalUrl.Contains(“https://abc”) –and ($_.PortalUrl -ne $null)){

$_.PortalUrl = $_.PortalUrl.Replace("https:// abc.", " https://xyz");

}

}
}
}


#---------------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------
#loop through a csv file
Import-Csv $inputFile | ForEach{                                
    $mainwebAppUrl = $_.MainWebAppurl  
    try
    {
  write-host "Updating Provisioning Url in portal site connection...."
        PortalSiteConnectionSettings $mainwebAppUrl
  write-host "Portal Site Connection Url has been updated" -ForegroundColor Green
    }
    catch
    {
  write-host "Completed with errors..."   
        Write-Output $_
    }
}
#---------------------------------------------------------------------------------------------------

#-----------------------------------------End Logging-----------------------------------------------
Stop-Transcript
#---------------------------------------------------------------------------------------------------

Note:
Before running this script,make sure that the account with which this script is executing is holding Farm admin privilege (or)
Before running this script,make sure that the account with which this script is  executing is member of admin group under every site collection of mentioned Web Application  

Wednesday, June 19, 2013

User Profile Import in SharePoint 2010

Hi,

I am posting the article of User Profile Import in SharePoint 2010 as below

2.1.1      Check the User Profile Service status

·         On the Central Administration Web site, in the System Settings section, click Manage services on server.
·         On the Services on Server page, in the Server box, select the synchronization server.
·         Find the row whose Service column value is User Profile Synchronization Service.
·         Check whether the value in the Status column is started.
If the value in the Status Column for the User profile synchronization service is started “Forefront Identity Manager Service” and“Forefront Identity Manager Synchronization Service” (which is available in Start | Run | services.msc) should be started automatically.                  

2.1.2      Create a synchronization connection to a directory service


To import profiles, you must have at least one synchronization connection to a directory service, create a synchronization connection to each directory service that you want to import profiles from. You can synchronize after you create each connection, or you can synchronize one time, after you have created all of the connections. Synchronizing after each connection will take longer, but doing this will make it easier to troubleshoot any problems that you might encounter.
The connection identifies the items to synchronize and contains the credentials that are used to interact with the directory service.
·         On the Central Administration Web site, in the Application Management section, click Manage service applications.
   
·         On the Manage Service Applications page, click on AZ ESP User Profile Service Application.
·         On the Manage Profile Service page, in the Synchronization section, click Configure Synchronization Connections.
  
abc & xyz Domain users will be imported to SharePoint User Profile Store and the following connection will be created,
1.     All abc Domain Users
2.     All xyz Domain Users

2.1.2.1  All AZ Domain Users

·         On the Synchronizations Connections page, click Create New Connection.
   
·         On the Add new synchronization connection page, type the synchronization connection name in the Connection Name asAll abc Domain Users.
·         In the Forest name box, type the name of the forest as abc.net.
·         Select “Auto domain discover controller” in the Connection Settings.
·         In the Authentication Provider Type box, select the type of authentication as Windows Authentication.
·         In the Account name box, type the synchronization account
·         In the Password box, type the password for the synchronization account.
·         In the Confirm Password box, type the password for the synchronization account again.
·         In the Port box, enter the connection port as 389.
·         Unselect Use SSL-secured connection.
·         In the Containers section, click Populate Containers, and then select the containers as shown in the below figure
·         Click OK.

2.1.2.1.1      Define exclusion filters for a synchronization connection


·         On the Central Administration Web site, in the Application Management section, click Manage service applications.
·         On the Manage Service Applications page, click the User Profile Service Application Name.
·         On the Manage Profile Service page, in the Synchronization section, select Configure Synchronization Connections.
·         On the Synchronization Connections page, Select the connection All abc Domain Users and then click Edit Connection Filters.
·         On the Edit connection filters page, in the Exclusion Filters for Users section, perform the following steps:
                      i.        Select userAccountControl from Attribute drop-down, select Bit on equals from Operator drop-down, enter 2 in Filter text box and then click on Add.
                              ii.            Select Any apply (OR) option in Exclusion Filters for Users.
                            iii.            Select division from Attribute drop-down, select Equals from Operator drop-down, enter 0 in Filter text box and then click on Add.
                            iv.            Select Any apply (OR) option in Exclusion Filters for Users.
                              v.            Select division from Attribute drop-down, select Equals from Operator drop-down, enter 15 in Filter text box and then click on Add.
                    vi.        Select Any apply (OR) option in Exclusion Filters for Users.
                   vii.        Select division from Attribute drop-down, select Equals from Operator drop-down, enter 17 in Filter text box and then click onAdd.
                  viii.        Select Any apply (OR) option in Exclusion Filters for Users.
                    ix.        Select division from Attribute drop-down, select Equals from Operator drop-down, enter 18 in Filter text box and then click onAdd.
                     x.        Select Any apply (OR) option in Exclusion Filters for Users.
                    xi.        Select division from Attribute drop-down, select Equals from Operator drop-down, enter 19 in Filter text box and then click onAdd.
                   xii.        Select Any apply (OR) option in Exclusion Filters for Users.
                  xiii.        Select division from Attribute drop-down, select Equals from Operator drop-down, enter 33 in Filter text box and then click onAdd.
                 xiv.        Select Any apply (OR) option in Exclusion Filters for Users.
                  xv.        Select division from Attribute drop-down, select Equals from Operator drop-down, enter 34 in Filter text box and then click onAdd.
                 xvi.        Select Any apply (OR) option in Exclusion Filters for Users.
                xvii.        Select division from Attribute drop-down, select Equals from Operator drop-down, enter 41 in Filter text box and then click onAdd.
               xviii.        Select Any apply (OR) option in Exclusion Filters for Users.
                 xix.        Select division from Attribute drop-down, select Equals from Operator drop-down, enter 49 in Filter text box and then click onAdd.
                  xx.        Select Any apply (OR) option in Exclusion Filters for Users.
                 xxi.        Select division from Attribute drop-down, select Equals from Operator drop-down, enter 62 in Filter text box and then click onAdd.
                xxii.        Select Any apply (OR) option in Exclusion Filters for Users.
               xxiii.        Select division from Attribute drop-down, select Equals from Operator drop-down, enter 63 in Filter text box and then click onAdd.
               xxiv.        Select Any apply (OR) option in Exclusion Filters for Users.
                xxv.        Select division from Attribute drop-down, select Is not present from Operator drop-down, then click on Add.


               xxvi.        Click on Ok.

2.1.2.2  All xyz Domain Users

·         On the Synchronizations Connections page, click Create New Connection.
   
·         On the Add new synchronization connection page, type the synchronization connection name in the Connection Name asAll abc Domain Users.
·         In the Forest name box, type the name of the forest as abc.com
·         Select “Auto domain discover controller” in the Connection Settings.
·         In the Authentication Provider Type box, select the type of authentication as Windows Authentication.
·         In the Account name box, type the synchronization account.
·         In the Password box, type the password for the synchronization account.
·         In the Confirm Password box, type the password for the synchronization account again.
·         In the Port box, enter the connection port as 389.
·         Unselect Use SSL-secured connection.
·         In the Containers section, click Populate Containers, and then select only the below containers as shown in the below table (abc->Accounts->Regions)
1
OU=OUName,OU=OUContainerName,OU=EU,OU=Regions,OU=Accounts,DC=xyz,DC=com
2
OU= OUName,OU= OUContainerName,OU=EU,OU=Regions,OU=Accounts,DC= xyz,DC=com
3
OU= OUName,OU= OUContainerName,OU=EU,OU=Regions,OU=Accounts,DC= xyz,DC=com
4
OU= OUName,OU= OUContainerName,OU=US,OU=Regions,OU=Accounts,DC= xyz,DC=com
5
OU= OUName,OU= OUContainerName,OU=US,OU=Regions,OU=Accounts,DC= xyz,DC=com
6
OU= OUName,OU= OUContainerName,OU=US,OU=Regions,OU=Accounts,DC= xyz,DC=com
7
OU= OUName,OU= OUContainerName,OU=US,OU=Regions,OU=Accounts,DC= xyz,DC=com
8
OU= OUName,OU= OUContainerName,OU=US,OU=Regions,OU=Accounts,DC= xyz,DC=com
9
OU= OUName,OU= OUContainerName,OU=US,OU=Regions,OU=Accounts,DC= xyz,DC=com
10
OU= OUName,OU= OUContainerName,OU=US,OU=Regions,OU=Accounts,DC= xyz,DC=com
11
OU= OUName,OU= OUContainerName,OU=US,OU=Regions,OU=Accounts,DC= xyz,DC=com
12
OU= OUName,OU= OUContainerName,OU=US,OU=Regions,OU=Accounts,DC= xyz,DC=com
·         Click OK.

2.1.2.2.1      Define exclusion filters for a synchronization connection

·         On the Central Administration Web site, in the Application Management section, click Manage service applications.
·         On the Manage Service Applications page, click the User Profile Service Application Name.
·         On the Manage Profile Service page, in the Synchronization section, select Configure Synchronization Connections.
·         On the Synchronization Connections page, Select the connection All xyz Domain Users and then click Edit Connection Filters.
·         On the Edit connection filters page, in the Exclusion Filters for Users section, perform the following steps:
              xxvii.        Select userAccountControl from Attribute drop-down, select Bit on equals from Operator drop-down, enter 2 in Filter text box and then click on Add.
                xxviii.            Click on Ok.

2.1.3      Schedule User Profile Incremental Synchronization


·         On the Central Administration Web site, in the Application Management section, click Manage service applications.
·         On the Manage Service Applications page, click in the Title column of the User Profile Service Application Name row to select it.
·         In the Operations group of the ribbon, click Manage.
·         On the Manage Profile Service page, in the Synchronization section, click Configure Synchronization Timer Job.
·         On the Edit Timer Job page, in the Recurring Schedule section, select the schedule as 1:00 AM to 2.00 AM, when you want recurring Profile Synchronization to occur and then click OK.

2.1.4      Configure Synchronization Settings

·         On the Central Administration Web site, in the Application Management section, click Manage service applications.
·         On the Manage Service Applications page, click in the Title column of the User Profile Service Application Name row to select it.
·         In the Operations group of the ribbon, click Manage.
·         On the Manage Profile Service page, in the Synchronization section, click Configure Synchronization Settings
·         On the edit Configure Synchronization Settings page, in Synchronization Entities section select Users Only option and then click OK