Sunday, March 24, 2013

Site Collection Restore Script

If we want to restore a single site collection through Powershell we use the following command:

Restore-SPSite "SiteURL" -path "Pathofbackupfile\backupfilename.bak" -Force -DatabaseServer DataBaseInstanceName -DatabaseName "ContentDataBase"

This will restore a single site collection. But if we have to restore many site collections then running the above command every time will not be feasible & is a waste of time.
Now the way out in this situation is to prepare a Powershell script & run the script once & it will restore all the site collections we want. This Powershell script reads the site URL, backup name, DataBase Server name & Content DataBase Name from a csv file. We will enter the url's & their respective backup file names, Server Name & ContentDataBase name in the csv file type & give the path of the csv file in the script. This script now reads the values one by one from each row & restores the site collections.
When the rows are finished from the csv file then it stops the script. In this way we can restore large number of site collections by running a single command.

The Powershell script is as follows:
$backupfolder= "Path of Backup files"
$filePath = "Path of .csv file"
$csv_info = Import-Csv $filePath
$count =$csv_info.count
#iterate Csv File
foreach ($line in $csv_info)
{
$siteurl = $line.SiteUrl.trim()
$DatabaseInstance = $line.DatabaseInstance.trim()
$ContentDatabase = $line.ContentDatabase.trim()
$backuppath = $backupfolder + "\" + $line.BackupPath.trim()
#cls
Restore-SPSite -Identity $siteurl -Path $backuppath -Force -DatabaseServer $DatabaseInstance -DatabaseName $ContentDatabase
#Write-Host $siteurl
Write-Host $backuppath
Write-Host "Sucess"
}
Save the file with the .ps1 extension. e.g.- "restorescript.ps1".
Create a csv file & insert the entries as follows
SiteUrl,BackupPath,DatabaseInstance,ContentDatabase
http://siteurl,siteurl.bak,InstanceName,WSS_Content_DBName
http://webapp/sites/siteurl2,siteurl2.bak,InstanceName,WSS_Content__DBName2
http://iconnectstaging/sites/siteurl3,siteurl3.bak,InstanceName,WSS_Content__DBName3
http://iconnectstaging/sites/siteurl4,siteurl4.bak,InstanceName,WSS_Content__DBName4

 When we have finished creating both the files, now open the Powershell Management tool & run a single command which contains only the path of the powershell script. e.g.- Restore-Path\restorescript.ps1.

The script will stop after all the site collection restoration is finished.

Restore Script with Site & Content Database Creation

$backupfolder= "Path of Backup files"
$filePath = "Path of .csv file"
$csv_info = Import-Csv $filePath
$count =$csv_info.count
#iterate Csv File
foreach ($line in $csv_info)
{
$siteurl = $line.SiteUrl.trim()
$DatabaseInstance = $line.DatabaseInstance.trim()
$ContentDatabase = $line.ContentDatabase.trim()
$backuppath = $backupfolder + "\" + $line.BackupPath.trim()
#cls
New-SPContentDatabase -Name $ContentDatabase -DatabaseServer $DatabaseInstance -WebApplication "http://demo" -MaxSiteCount 1 -WarningSiteCount 0
New-SPSite $siteurl -OwnerAlias "spad\farmadmin" –Language 1033 -Template "STS#0" -ContentDatabase $ContentDatabase
Restore-SPSite -Identity $siteurl -Path $backuppath -Force -DatabaseServer $DatabaseInstance -DatabaseName $ContentDatabase -confirm

#Write-Host $siteurl
Write-Host $backuppath
Write-Host "Sucess"
}


Site Collections Backup Script

If we want to take backup of a single site collection through Powershell we use the following command:

Backup-SPSite "http://sitecollectionurl" -Path "PhysicalPath\backupname.bak"

This will take the backup of a single site collection. But if we have to take the backup of many site collections then running the above command every time will not be feasible & is a waste of time.
Now the way out in this situation is to prepare a Powershell script & run the script once & it will take the backup of all the site collections we want. This Powershell script reads the site URL & the backup name from a csv file. We will enter the url's & their respective backup file names in the csv file type & give the path of the csv file in the script. This script now reads the values one by one from each row & takes the backup.
When the rows are finished from the csv file then it stops the script. In this way we can take the backup of large number of site collections by running a single command.

The Powershell script is as follows:

$backupfolder= "Folder Path where the backup is to be stored"
$filePath = "Path of the .csv file"
$csv_info = Import-Csv $filePath
$count =$csv_info.count
#iterate Csv File
foreach ($line in $csv_info)
{
$siteurl = $line.SiteUrl.trim()
$backuppath = $backupfolder + "\" + $line.BackupPath.trim()
#cls
Backup-SPSite -Identity $siteurl -Path $backuppath -Force
#Write-Host $siteurl
Write-Host $backuppath
Write-Host "Sucess"
}  
Save the file with the .ps1 extension. e.g.- "backupscript.ps1".

Create a csv file & insert the entries as follows:

SiteUrl,BackupPath
http://siteurl,siteurl.bak
http://webapp/sites/siteurl2,siteurl2.bak
http://webapp/sites/siteurl3,siteurl3.bak
http://webapp/sites/siteurl4,siteurl4.bak

When we have finished creating both the files, now open the Powershell Management tool & run a single command which contains only the path of the powershell script. e.g.- Backup-Path\backupscript.ps1.

The script will stop after all the site collection backup is finished.

Thursday, March 14, 2013

Enable Developer Dashboard


SharePoint 2010 has many new features, among them, the Developer Dashboard. This is a dashboard for analyzing the execution and performance of the current page. The information provided will execution time of queries and events to more general information as the user logged on or page state.

By default this feature is not enabled. You can choose between four methods to activate it: a STSADM command, a PowerShell script, a .NET code or the Developer Dashboard configuration feature.
There are three levels of activation:
  • Off: Disabled, this is the default value.
  • On: The feature is available on all pages
  • OnDemand: An icon is displayed on the pages to enable or disable the feature.
The state OnDemand is, in my opinion, the most practical because you can do this only on the pages under development.

This operation requires that you be administrator of the SharePoint farm.


STSADM

    stsadm -o setproperty -pn developer-dashboard -pv on
    stsadm -o setproperty -pn developer-dashboard -pv off
    stsadm -o setproperty -pn developer-dashboard -pv OnDemand (recommended)

PowerShell

$svc=[Microsoft.SharePoint.Administration.SPWebService]::ContentService
$ddsetting=$svc.DeveloperDashboardSettings
$ddsetting.DisplayLevel=[Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::OnDemand
$ddsetting.Update()

Refer:


http://en.hugon.ws/articles/sharepoint-2010/using-the-developer-dashboard/
http://blogs.technet.com/b/patrick_heyde/archive/2009/11/16/sharepoint-2010-enable-using-developer-dashboard.aspx
http://blogs.technet.com/b/patrick_heyde/archive/2009/11/16/sharepoint-2010-enable-using-developer-dashboard.aspx

IIS Bindings & Assigning Host Header to Web Application


All about site bindings
Microsoft’s Internet Information Services (IIS) has been built around a very flexible “binding” system. 
When working with a website a “binding” is the combination of protocol (http, ftp, https, etc.), IP address, TCP/IP port and host name– which is basically a domain name.  In IIS7 the protocol is referred to as the “Type” of binding. 
The binding is then associated with a website which allows IIS to properly route incoming traffic to the correct site.  The IIS binding implementation also allows multiple bindings per site.
An IIS binding uses the following shorthand notation.
<protocol> <IP address>:<port>:<host name>
In order for IIS to transfer a page request to a site all conditions in one of the site binding(s) must be met.  If no binding is found you get the  404 error.
Go to run ,type,inetmgr,locate the site for which you want to assign new host name
Edit bindings,add new binding below dialog will appear: 

For example, the site binding for http://www.test.com could look like this.
Type:http
IP Address :172.20.1.133
Port :80
Hostname :www.test.com


Binding rules
The binding rules can be summarized like this:
1. Find all bindings with a matching protocol.
2. Filter by port.
3. Try to match the requested domain name to a host name.
4. Match by IP address.
The rules on how each element in the bindings is configured and matched requires a more detailed discussion.
The protocol, or binding type, and port are always required in a binding and have a rigid set of rules, but the other fields offer some flexibility.  The protocol must always be an IIS recognized protocol type, such as http, https, ftp, etc. and the port must always be an integer (whole number) from 0 to 65535.  Be careful of the port you use as the ORCS Web perimeter firewall will block all incoming non-standard ports unless a custom firewall rule is applied.  The IP address has a little more flexibility in the form of a wildcard, which, for IIS, is an asterisk (*).
When an asterisk is used instead of an IP address the binding will apply to the site if the other three binding conditions are met.  In the IIS binding drop-down the wildcard option is called “All Unassigned” (see fig. 1).  Be careful when using an IP address wildcard as a similar binding with an actual IP address will take precedence over the wildcard.  The host name, or domain name, field is the only part of the binding that is optional in the UI and provides the greatest flexibility.
Host names, or host headers as they were called in IIS6, allow you to serve many sites from a single IP address.  It is common to see a dedicated server with a single IP address host a dozen individual sites through the use of host names.  When a host name is used, however, IIS will only pass the request if theexact domain name entered matches the host name exactly – where the domain name is the part between “://” and the first “/”, i.e. in http://www.orcsweb.com/blog the domain name is www.orcsweb.com.  This domain name to host name matching is not case-sensitive, only character sensitive.
When using host names it is important that you to analyze how clients may type in your domain name and create a host header binding for each scenario you wish to support.  For example, if you have a domain, orcsweb.com, that shares an IP address with other sites on a server you will want to create two bindings; one binding for orcsweb.com and a second binding for www.orcsweb.com.  The binding shorthand for the above example would look like this.
http *:80:orcsweb.com
http *:80:www.orcsweb.com
When only a single site uses an IP address it is not necessary to use host names at all.  If there is no host name IIS will disregards the domain name all together and assigns the request based on protocol, IP and port; however, if a different site has a matching host name the request will go there instead.  A matching host name, even with a wildcard IP, will take priority over an IP address with no host name binding.
http 66.129.79.227:80:
http *:80:www.orcsweb.com [this binding will have priority over the above binding if the requested domain name is www.orcsweb.com]
The shortest possible binding is reserved for servers with a single IP and site, or if you wish to have a “catch-all” site when no other binding fits.  This binding, which uses the IP wildcard and no host header, would be applied absolutely last when no other binding match could be found.  In this case the binding will simply be:
http *:80:
One final rule for bindings, you should not use the same binding twice on a server.  Each binding on a server must be unique or IIS will be unable to determine where to send the request. If you do manage to add duplicate bindings, and there are a couple of ways to do it, one of the sites will be stopped by IIS. You will be unable to start both sites until the binding conflict is removed. The IIS Manager will give you a warning if you try to enter a duplicate binding so there is little to worry about, but it is something you should be aware of, especially when working with secure sites.
If you use IIS6, or do not have access to IIS Manager for an IIS7 site, you are welcome to send the ORCS Web support team any binding setup requests you may need.  While you do not have to put the request into binding shorthand, this article should provide you with the knowledge needed to decide what sort of bindings your site(s) may need.
Secure site bindings
When setting up a secure site, one that uses an SSL certificate to encrypt the data stream, all of the binding rules from above are still valid but there are special circumstances that must be taken into account.  The primary factor behind this stems from rule number one of secure site bindings: no IP address sharing is allowed unless you have a wildcard certificate or use a non-standard port.  A traditional secure site binding will look something like this:
https 66.129.79.227:443:
While some sites and blogs show workarounds that allow multiple secure sites per IP we highly discourage this unsupported behavior.  Modifying the configuration files to break rule #1 will cause all modern web browsers to throw certificate errors when entering your secure site, and that is not only a bad practice but could discourage customers from using your site.
Secure sites are bound to port 443 by default.  It is only on very rare occasion that this port number should be changed.  Corporations with perimeter firewalls almost always keep port 443 open for secure browsing and then block all non-standard ports.  While changing the https port from 443 will allow you to host multiple secure sites on a single IP address you first, add difficulty for the customer who needs to remember adding a port to your domain name (i.e. www.orcsweb.com:4443) and second, you run the risk of being blocked by corporate firewalls.
This port paradox is the primary reason why you generally need one IP per secure site per server since the bindings on a server must be unique and without host headers there is only one possible binding combination on the standard port. Unless you are designing a secure site for a very specific set of users you should not us a non-standard secure port.
A quick word of caution about wildcard certificates and https bindings: if the certificate Name does not include "*." before the domain name IIS7 will not allow you to use https host names through the UI. Even if the certificate "issued to" contains *.domainname.com it will not work.  There are ways to get it working through the command line or by directly modifying the binding in applicationHost.config so there is no concern for alarm if the wildcard certificate name does not contain "*.".
When requesting, or setting up, a secure site binding the only information needed is the site, the IP address and which certificate to use.  If you have a wildcard certificate, i.e. *.orcsweb.com, then a host header value can be assigned as well.  For information on how to obtain an SSL certificate please refer to this KB article.
While this article does not cover every possible scenario and detail it should provide a solid foundation to understanding bindings.  Bindings are an excellent resource at your disposable to maximize your hosting investment.  If you are interested in learning more about this topic here are links to some of Microsoft’s online resources.

http://technet.microsoft.com/en-us/library/cc753195(WS.10).aspx
http://technet.microsoft.com/en-us/library/cc731692(WS.10).aspx
http://learn.iis.net/page.aspx/101/introduction-to-iis-7-architecture/
http://msdn.microsoft.com/en-us/magazine/cc163357.aspx

Hoat A or DNS Entry : Configuring Application URL


If you are working on Microsoft Web based Solutions such as SharePoint. you would know that on installation these products take up the server FQDN + Service Port as their primary access URL. Wouldn’t it be good if we could have meaningful access URL(s) for each service (CRM, SharePoint) even if they are running on the same physical or virtual server.
For that we need to create a alias for the server running the service in the DNS. You need to have the access to the DNS Server as an Administrator to be able to do that.
Lets take a look at how can that be done.
  1. Go to DNS manager, and expand the node of the DNS Server you want to add the entry to.
  2. Next Expand the “Forward Lookup Zone” node .
  3. Right click on the node with the name of your Domain.
  4. Select “New Host (A or AAAA)” option.
  5. Enter the detais as illustrated belowimage
    1. Name : Enter the new name of the URL, for Eg, if you want your service to be accessed via “manoj.mydomain.com”, then enter “manoj” as the Name.
    2. IP address : Enter the IP Address of the Server running the service.
  6. Click on Add Host.

Host File Entry

Host entry needs to be done on Hosts file located in both WFE Server & INDEX Server of Production server.A host name always corresponds to an IP address that is stored in a HOSTS file to identify default gateway.

Steps To Locate Hosts File & Making Host Entry

1. Go to Start
2. Run
3. Type Drivers and Press Enter
               C:\WINDOWS\system32\drivers
4. Open etc Folder >Locate Hosts file and open in Notepad .
     Below screen will appear
5. Add two host entry  : 10.71.17.184 manoj:80
                                     10.71.17.185 manoj:80
6. Save file

Note: Make copy of Hosts file before making changes.

Refer 
http://www.timeatlas.com/term_to_learn/general/taking_control_with_the_hosts_file#.UUF1kp1_42Q
http://www.accs-net.com/hosts/how_to_use_hosts.html
http://en.wikipedia.org/wiki/Hosts_(file)


Wednesday, March 13, 2013

Alternate access mapping & Registry settings.


To configure alternate access mapping follow the below steps
-          Open Central Administration
-          Click on Configure Alternate Access mappings link on right navigation




Now click on Site URL for which you want to configure alternate access mapping.
You will see below screen. Here you need to enter the required name for the site to access and select zone that you want to in order to configure alternate access mapping.



If you have configured alternate access mapping then you also need to do following registry entries.

Refer :


 http://technet.microsoft.com/en-us/library/cc261814(office.12).aspx
 http://www.mssharepointtips.com/tip.asp?id=1102&page=2



There are 3 Registry settings:

 1)     BackConnectionHostNames
>Go to Run
>Type Regedit
>Path: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
> Right-click MSV1_0, point to New, and then click Multi-String Value.
Type BackConnectionHostNames, and then press ENTER.
                Right-click BackConnectionHostNames and then click Modify.

  >In the Value data box, type the host name and then click OK.
eg: Host name manoj.
  >Quit Registry Editor


 2)     DisableLoopBackCheck
>Go to Run
>Type Regedit
>Path: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\
> Right-click Lsa, point to New, and then click DWORD Value.
Type DisableLoopBackCheck, and then press ENTER.
                Right-click DisableLoopBackCheck, and then click Modify.

  >In the Value data box, type 1, and then click OK.
  >Quit Registry Editor

  3)     DisableStrictNameChecking
>Go to Run
>Type Regedit
>Path: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\LanmanServer\Parameters
>Edit  menu, click Add Value, and then add the following registry value:

Value name: DisableStrictNameChecking
Data type: REG_DWORD
Value: 1

>Quit Registry Editor

Refer:
http://technet.microsoft.com/en-us/library/ff660057(v=ws.10).aspx
http://support.microsoft.com/kb/926642
http://www.harbar.net/archive/2010/02/12/groundhog-day-configuring-back-connection-host-names-using-group-policy.aspx
http://www.happysysadm.com/2011/11/setting-disablestrictnamechecking-in.html

Distributed cache in SharePoint Farm

During maintainence and operational work there is specific sequence that needs to be followed for Dsitributed cache to disconnect and conne...