Thursday, November 19, 2015

Configuring SQL Server Log Shipping on SharePoint Content Databases

Introduction to Log Shipping
Log shipping enables you to configure SQL Server to continually send transaction log backups on from a primary database on a primary server instance to one or more secondary databases on separate secondary server instances. The transaction log backups are applied to each secondary database individually. Continually backing up the transaction logs from a primary database and then copying and restoring them to a secondary database keeps the secondary database almost synchronized with the primary database. Log shipping can also include an optional third server instance, known as the monitor server, that records the history and status of backup and restore operations and raises alerts if these operations do not occur as scheduled.
Log shipping consists of three jobs. Each job performs one of the following operations:
  1. Backs up the transaction log at the primary server instance
  2. Copies the transaction log file to the secondary server instance
  3. Restores the log backup on the secondary server instance

Implementing data redundancy is one of the most effective ways to avoid data loss in any application. Although this article discusses configuring redundancy for SharePoint content stored in SQL Server by configuring SQL Server log shipping, redundancy should not be limited to only data redundancy. Any possible single point of failure, including hard drives, cables, and DNS or IIS entries should be taken into consideration to ensure you are able to quickly recover from what could be a disaster.

There are several methods to choose from when determining the type of data redundancy you need to ensure business continuity. A few of these methods include; SQL Server clustering, database mirroring, AlwaysOn, and SQL Server log shipping all of which are managed by your SQL Server DBA's who are responsible for the SQL Server environment.
Log shipping provides both server-level redundancy as well as data redundancy, because you have an entire server (usually referred to as the secondary server) dedicated to hosting a copy of your SharePoint Web app content databases, service application databases, and your SharePoint configuration settings. This secondary server is very helpful if you need to quickly failover it in the event your primary SQL Server server fails. The secondary server can also be used to perform DBCC (Database Console Commands) to verify the integrity of your SharePoint databases instead of letting the secondary server just sit their idle waiting for the primary server to fail.
To configure SQL Server log shipping you must first stand-up a second server which is the secondary server that will mirror the configuration of your primary SQL Server server. After the primary server is made available, you can then create automatic shipments of the transaction logs from the primary server to the secondary server. You can use the upcoming steps to configure SQL Server log shipping for your SharePoint content databases from the primary server to the secondary server.
Note: In the following configuration, SQLPrimary is the primary SQL Server server and SQLBackup is the secondary SQL Server server. We will begin by creating a SQL Server alias called SPSQL_Instance which can be used to failover to theSQLBackup secondary server.
  1. Create a SQL Server alias called SPSQL_Instance by opeing the SQL Server Configuration Manager.
  2. Expand SQL Server Native Client Configuration, then right-click Aliases, and click New Alias.
  3. Type in SPSQL_Instance in the Alias Name box, then type SQLPrimary in the Server box then click OK. (Alternatively, you can enter the IP address instead of the server name.)
  4. Login to the secondary SQL Server, named SQLBackup, and create a folder called LogShipping and share the folder with a network share name of LogShipping
  5. On the primary SQL Server, named SQLPrimary, open SQL Server Management Studio (SSMS), and add the SharePoint farm administrator domain account to the security logins and also map the SharePoint farm administrator domain account to the dbo role of each SharePoint content database.
  6. If the SQL Server Agent is not started on both SQL Server servers, start it, and also make sure the SQL Server Agent is configured to automatically start on both of these SQL Server servers.
  7. On SQLPrimary SQL Server locate the database that you want to configure log shipping for and right-click on the SharePoint content database and click Properties.
  8. Select Transaction Log Shipping, and then select Enable this as a Primary database in a log shipping configuration.
  9. Click Backup Settings and enter \\SQLPrimary\LogShippng
  10. Click the Schedule button and change Daily Frequency Occurs Every: to 5 minutes, and then click OK.
  11. In the Secondary Databases section, click Add and then click the Connect button to connect to the SQLBackup SQL Server server. Verify your SharePoint content database name is selected as the Secondary database for log shipping configuration.
  12. Click the option: Yesgenerate full backup of the primary database and restore it into the secondary database (and create the secondary database if it doesn’t exist)
  13. Click Restore Options and type the location of the data file and the log file on the secondary SQL Server server. (Preferably, you would enter different drives; one for the data file and one for the log file)
  14. On the Copy Files tab type in \\sqlBackup\LogShipping, (or the share name you created on the secondary SQL Server server.
  15. Click the Schedule button and change the Daily frequency Occurs every: to 5 minutes
  16. On the Restore Transaction Log tab click the Standby Mode radio button and click the check box next to Disconnect users in the database when restoring backups. Otherwise the transaction logs will not be applied until later. ClickOK.
  17. Optionally, on the Database Properties Select the Script Configuration button and choose Script Configuration to Clipboard, open Notepad and paste the log shipping configuration information and then save it to a location in the event you want to use it again later.
  18. Click OK, and then click Close after completion.
  19. Go to the SQLBackup SQL Server server and refresh the databases node to see that your SharePoint content database is set to standby / read only mode.
In the event the SQLPrimary SQL Server server fails you simply modify the SPSQL_Instance alias to point to theSQLBackup SQL Server so that server now responds to all SQL Server server requests.

Sunday, November 15, 2015

Troubleshooting the Sharepoint 2010 User Profile Service Application

Sharepoint 2010 User Profile Service (UPS) application allows the Sharepoint administrator great flexibility and is a "must have" feature if you are taking your Sharepoint to the next level.


Unfortunately UPS has a dark side that too many administrators have to face at one time or another, more often than not it is related to the "Forefront Identity Management Service" and the "Forefront Identity Manager Synchronization Service" service.

Some Tips 

  • Upgrade to Sharepoint 2010 SP1 and the August 2011 CU at before attempting to resolve problems. Both of these updates resolve a number of issues that might impact the User Profile Service application.
  • Don't ever try to change the "Forefront Identity Manager Service" or "Forefront Identity Manager Synchronization Service" settings manually from the Services MMC snap-in. It simply doesn't work as SP needs to do a great deal of configuration.
  • Sharepoint can be super slow, sometimes you need to wait 10-15 minutes for things to happen, so when you click start and nothing happens, wait 15 minutes then check again.
  • If you are re-creating the User Profile Service application, it is a good idea to use different names for the databases, the service application itself and the application pool. This will ensure there are no conflicts with any old settings that may be floating around in your Sharepoint configuration or registry.
  • Be IISRESET "happy". It is a good idea to perform IISRESET's after major parts of the setup process. I normally follow a pattern such as: Start/Create the service, wait 10 minutes, IISRESET, next step. This will ensure all of Sharepoint is "on the same page" before moving forward to the next step of the process.


Possible Issues and Resolutions 

    Problem:
    After starting the "User Profile Synchronization Service" from Central Administration only the "Forefront Identity Manager Synchronization Service" starts, or both services fail to start.

    Resolution: 
    If you don't have too much already setup in the UPS or it is your first time setting it up, it can be much easier to delete the UPS, stop the Synchronization services and then recreate it, than mess around. See my rebuild process below.


    Problem:
    "Forefront Identity Manager" source logs an Event ID 3 in event logs.
    .Net SqlClient Data Provider: System.Data.SqlClient.SqlException: HostId is not registered
    Resolution:
    Most of the time simply restarting the "Forefront Identity Manage Service" and "Forefront Identity Manager Synchronization Service" from the services MMC snap-in will resolve this issue. If either of them is in a Disabled state or the problem persists after a service restart, then I recommend rebuilding the UPS from scratch as per my instructions below.


    Problem:
    "ILM Web Service Configuration" source logs an Event ID 234 in event logs.
    ILM Certificate could not be created: Cert step 2 could not be created: C:\Program Files\Microsoft Office Servers\14.0\Tools\MakeCert.exe -pe -sr LocalMachine -ss My -a sha1 -n CN="ForefrontIdentityManager" -sky exchange -pe -in "ForefrontIdentityManager" -ir localmachine -is root
    Resolution:
    If you have tried to provision the "User Profile Synchronization Service" a number of times you might see this error. It occurs because there are multiple "ForefrontIdentityManager" certificates stored in the Certificate store.

    Firstly you need to stop the "User Profile Synchronization Service" under Sharepoint Central Administration > System Settings > Manage Services on Server.

    Then open an MMC console, add a Certificates snap-in, select Computer Account. Check the Personal, Trusted Root Certification Authorities and Trusted People stores for duplicate "ForefrontIdentityManager" certificates and delete ALL the FIM certificates.

    Next under Sharepoint Central Administration > System Settings > Manage Services on Server, Start the "User Profile Synchronization Service" again, you will be prompted for the password of the Sharepoint service account it is using. It should successfully restart and create a new certificate without conflicts.


    Problem:
    "Microsoft Resource Management Service" source logs a Event ID 0 in event logs.
    Service cannot be started. System.InvalidOperationException: Cannot find the X.509 certificate using the following search criteria: StoreName 'My', StoreLocation 'LocalMachine'
    Resolution:
    The "User Profile Synchronization Service" can't find a certificate when it is starting. You need to stop and then start this service. Firstly you need to stop the "User Profile Synchronization Service" under Sharepoint Central Administration > System Settings > Manage Services on Server. After waiting 5 minutes, perform an IISRESET and then press Start to restart the service. You will be prompted for the password of the Sharepoint service account it using.


    Problem: 
    "Microsoft.ResourceManagement.ServiceHealthSource" source logs an Event ID 2 in event logs.
    The Forefront Identity Manager Service could not bind to its endpoints.  This failure prevents clients from communicating with the Web services.
    Resolution:
    You can try restarting the "Forefront Identity Manage Service" and "Forefront Identity Manager Synchronization Service" from the services MMC snap-in. If this does not work then I recommend rebuilding the UPS from scratch as per my instructions below.


    Problem:
    "Forefront Identity Manager" source logs an Event ID 3 in event logs.
    .Net SqlClient Data Provider: System.Data.SqlClient.SqlException: Cannot open database "DBNAME" requested by the login. The login failed.
    Login failed for user 'DOMAIN\service-spsql'
    Resolution:
    This issue occurs if you have recreated the User Profile Service application and the database settings have not updated in the registry. It is normally a smart idea to stop the "User Profile Synchronization Service" under Sharepoint Central Administration > System Settings > Manage Services on Server, wait 5 minutes, then restart it.

    If it is simply a database name wrong you can edit it in the registry under the following paths.
    HKLM\system\currentcontrolset\services\FIMService
    HKLM\system\currentcontrolset001\services\FIMService
    HKLM\system\currentcontrolset002\services\FIMService
    HKLM\system\currentcontrolset\services\FIMSynchronizationService
    HKLM\system\currentcontrolset001\services\FIMSynchronizationService
    HKLM\system\currentcontrolset002\services\FIMSynchronizationService
    The main two values you will want to look at are "DatabaseName" and "DatabaseServer", ensure those two are correct then restart the "Forefront Identity Manage Service" and "Forefront Identity Manager Synchronization Service" from the services MMC snap-in.

    If this doesn't work, then stopping the "User Profile Synchronization Service"and then restarting it from Central Administrator is your best solution.


    Problem: 
     "User Profile Service" source logs an Event ID 1511 in event logs. The "event user" will be one of your Sharepoint service accounts.
    Windows cannot find the local profile and is logging you on with a temporary profile. Changes you make to this profile will be lost when you log off.
    Resolution:
    This is a fairly common problem and one of the easier ones to fix. Firstly go into your IIS management console > Application Pools and search for any application pools that have the same username as the event log user. Stop all of those application pools and then run an IISRESET.

    Then from the command line run the commands. The first command adds the problem user account to the local administrator group (to aide the profile creation) and the second command creates the user profile.
    net localgroup administrators DOMAIN\AppPoolAccount /add
    runas /u:DOMAIN\AppPoolAccount /profile cmd
    When this process is complete remove the user from the local administrators group.
    net localgroup administrators DOMAIN\AppPoolAccount /delete
    Then you will need to restart all the IIS Application Pools you previously stopped.


    Problem:
    After adding a "Synchronization Connector" to the UPS you can no longer get into "Manage User Profiles". When clicking "Manage User Profiles" the web browser simply times out with no errors in the event log or ULS logs.

    Resolution:
    Unfortunately I am still struggling with this one and have no resolution. On the other hand it seems to make no difference, unless you want to map custom properties, which you can do manually through the Forefront Identity Manager console from the Sharepoint server desktop. While it is annoying to not be able to access, it doesn't seem to have any functional restrictions, in my environment at least.


    Recreating the User Profile Service application

    1. First we need to get rid of the broken instance of UPS.
    a. Under Central Administration > System Settings > Manage services on server, stop the "User Profile Service" and "User Profile Synchronization Service"
    b.  Under Central Administration > Application Management > Manage service application, delete the "User Profile Service application"
    c.  On the Sharepoint server itself, open an MMC console, add a Certificates snap-in, select Computer Account. Check the Personal, Trusted Root Certification Authorities and Trusted People stores for "ForefrontIdentityManager" certificates and delete ALL the FIM certificates.
    d.  Open a Sharepoint 2010 Management Shell, issue the command get-spserviceapplicationpool. Remove any service application pools that are associated with previous UPS applications with the command:
    remove-spserviceapplicationpool "PoolName"
    e.  Delete any pending timer jobs related to the UPS synchronization service provisioning. Under Central Administration >Monitoring > Check job status, check the Running section for any related jobs and delete them.
    f.  Wait 15 minutes and then issue an IISRESET before proceeding to the next step.

    2. Under Central Administration > System Settings > Manage services on server, start the "User Profile Service.

    3.  Under Central Administration > Application Management > Manage service application, create a new UPS. Use a different name than you did for the previous UPS instance, different database names and a different application pool name. Wait 15 minutes then issue an IISRESET.

    4. Under Central Administration > System Settings > Manage services on server, start the User Profile Synchronization service. Wait 15 minutes and if both FIM services are running from an MMC services snap-in as below, issue an IISRESET.

    If you get this far and have no problems opening your UPS application from Central Administration > Application Management > Manage service application then congratulations, more than likely you have resolved your problems.

    You can now proceed to adding Synchronization connectors and bringing those attributes in from Active Directory.

    Wednesday, October 7, 2015

    Search Service Application

    • Provisioning the Search Service Application
    • Moving Query Components
    • Creating Mirror Query Components
    • Creating Query Components
    • Creating Crawl Components
    • Creating Crawl Databases
    • Creating Property Databases
    Provisioning the Search Service Application
    Open SharePoint 2010 Central Administration.
    Select Managed service applications under Application Management.
    Select New | Search Service Application on the ribbon user interface.
    CA
    On the Create Search Service Application dialog specify the name for the new Search Service Application or accept the default name, usually Search Service Application 1.
    Provide a name for the new Search Administration Web Service Application Pool or use an existing Application Pool.
    Provide a name for the new Search Administration Site Settings and Query Web Service or use an existing Application Pool.
    CA2
    Click OK on the new Create New Search Service Application dialog to provision the new service application
    Once the Search Service Application has been successfully provisioned on the server farm you will have a 1x1x1 topology or otherwise 1 Search Administration, 1 Crawl, and 1 Query component on the machine hosting SharePoint 2010 Central Administration and all associated databases on the default database server.
    Topology
    NOTES
    The Search administration (Admin) topology does not scale out - there can be on one (1) search administration component and one (1) search administration database per Search Service Application.
    The Crawl topology can be scaled out by adding Crawl Components or Crawl Databases.  Crawl Components can have a many-to-one relationships with Crawl Databases.
    The Query topology can be scaled out by adding Property Databases or by adding Query Components.  Index Partitions subdivide the full-text index.   A new Query Component can either be the first component in a new partition (see above illustration (Query Component 0)) or an additional component in an existing partition.
    In the public beta, Index Partitions have a many-to-one relationship with Property Databases.
    Moving Query Components
    Open SharePoint 2010 Central Administration.
    Select Managed service applications under Application Management.
    On the Services Applications page, select the Search Service Application.
    On the Search Administration page, locate the Search Application Topology section and click Modify.
    On the Topology for Search Service Application: Search Service Application page, locate the Index Partition category. (The default Query Component is typically named Query Component 0). Click Query Component 0 and then click Edit Properties.
    On the Edit Query Component page, select a server in the topology from the Server drop-down list and then click OK.  This will move the Query Component to the selected server.
    EditQueryComponent
    Creating Mirror Query Components
    When you create a Mirror Query Component, you create a replica of the Index Partition on another server.  You will typically create new Mirror Query Components when you need to increase throughput or availability.
    Open SharePoint 2010 Central Administration.
    Select Managed service applications under Application Management.
    On the Services Applications page, select the Search Service Application.
    On the Search Administration page, locate the Search Application Topology section and click Modify.
    On the Topology for Search Service Application: Search Service Application page, locate the Index Partition category. (The default Query Component is typically named Query Component 0). Click Query Component 0and then click Add Mirror.
    AddMIrror
    On the Add mirror query component dialog, select a server in the topology from the Server drop-down list and then click OK.
    AddMirrorComponent 
    Repeat the steps for each server in the topology as required.
    Creating Query Components
    When you create a new Query Component, you create a new Index Partition which subdivides the full-text index.  You will typically create new Query Components and Index Partitions when the total number of items in your Index exceed the recommend scale for a single Index Partition, or when you need to increase throughput or availability.
    Open SharePoint 2010 Central Administration.
    Select Managed service applications under Application Management.
    On the Services Applications page, select the Search Service Application.
    On the Search Administration page, locate the Search Application Topology section and click Modify.
    On the Topology for Search Service Application:  Search Service Application 1, select New | Index Partition and Query Component.
    Topology2
    On the Add Query Component dialog, select a server in the topology from the Server drop-down list, Property Database, and specify the location of the Index Partition.
    AddQueryComponent
    Click OK on the Add Query Component dialog to save the changes and create the new Query Component.
    Creating Crawl Components
    You will typically create new Crawl Components to improve the overall crawl speed and subsequently freshness of the content and to improve availability.
    Open SharePoint 2010 Central Administration.
    Select Managed service applications under Application Management.
    On the Services Applications page, select the Search Service Application.
    On the Search Administration page, locate the Search Application Topology section and click Modify.
    On the Topology for Search Service Application:  Search Service Application 1, select New | Crawl Component.
    Topology2
    On the Add Crawl Component dialog specify the server where the Crawl Component will be hosted, the Crawl Database to which the Crawl Component will be associated, and the temporary location on the Index.
    AddCrawlComponent
    Click OK on the Add Crawl Component dialog to save the changes and create the new Crawl Component.
    Creating Crawl Databases
    You will typically create new Crawl Databases to improve the overall crawl speed and subsequently freshness of the content and in correlation to the creation of new Crawl Components.
    Open SharePoint 2010 Central Administration.
    Select Managed service applications under Application Management.
    On the Services Applications page, select the Search Service Application.
    On the Search Administration page, locate the Search Application Topology section and click Modify.
    On the Topology for Search Service Application:  Search Service Application 1, select New | Crawl Database.
    Topology2
    On the Add Crawl Database dialog specify the database server where the Crawl Database will reside, the database name, and optionally the select whether the Crawl Database will be dedicated to hosts specified in Host Distribution Rules.
    Host Distribution Rules are useful in specifying:
    1. A particular host that is processed by a one or more Crawler Databases.
    2. A particular host is processed by only one or more Crawler Database.
    Host Distribution Rules are commonly used to support large and complex content corpuses that require horizontal scale (scale out) topologies.
    AddCrawlDB
    Click OK on the Add Crawl Database dialog to save the changes and create the new Crawl Database.
    Creating Property Databases
    You will typically create new Property Databases to support the horizontal scale (scale out) of the Query Component(s).
    Open SharePoint 2010 Central Administration.
    Select Managed service applications under Application Management.
    On the Services Applications page, select the Search Service Application.
    On the Search Administration page, locate the Search Application Topology section and click Modify.
    On the Topology for Search Service Application:  Search Service Application 1, select New | Property Database.
    Topology2
    On the Add Property Database dialog specify the database server where the Property Database will reside and the database name.
    AddPropertyDatabase
    Click OK on the Add Property Database dialog to save the changes and create the new Property Database.

    Saturday, August 1, 2015

    Configure Search Service Application

    Configure Search Service Application


    SharePoint 2013 Search Architecture and Components

    SharePoint 2013 Search with an even improvised architecture. The FAST Search has been integrated with SharePoint 2013.SharePoint Search is further componentized now.

    There are 6 Search Components and 4 Search Databases.

    Before you read this, I would say complete wipe off the previous Search concepts from your mind. Though the underlying Search architecture is same, it is better to start fresh.

    In a nutshell the six Search Components are:

    1)   Crawl Component

    2)   Content Processing Component

    3)   Index Component

    4)   Query Processing Component

    5)    Administration Component

    6)    Analytics Processing Component

    The databases associated with Search are:

    1)    Crawl DB

    2)    Search Administration DB

    3)    Link DB

    4)   Analytics DB

    Crawl and Component Process

    1) Crawl Component [CC]
    The Crawl Component crawls the content sources and delivers the crawled items [the content and the metadata] to Content Processing Component. Crawl Component uses the Crawl DB to store information about crawled items [like last crawl time, historical information about crawled items etc.]

    2) Content Processing Component [CPC]
    Content Processing Component is placed between the Crawl Component and Index Component. The crawled items are processed by the Content Processing Component and fed into the Index Component. The processes include document parsing and property mapping.

    Index and Query Process

    3) Index Component [IC]
    The Index Component gets the processed items from the Content Processing Component and writes it to an index file. The Index component receives the queries from the Query Processing Component and provides the results sets

    4) Query Processing Component [QPC]
    The Query Processing Component is placed between the front end and the Index Component. It analyses and processes search queries and results. The processed search query is submitted to the Index Component. The Index Component returns the result set based on the processed query to the Query Processing Component. This result is send to the front end by the Query Processing Component.

    Search Administration

    5) Administration Component [AC]
    The Search Administration Component is responsible for running the system processes essential to search. It does the provisioning part [adding and initializing search components] .The Administration Component uses the Search Administration DB. We can have multiple Administration Component for a Search Service application. But at a time, only one would be active.
    Analytics Process

    6) Analytics Processing Component [APC]
    Analytics Processing Component analyzes the crawled items (search analytics) and how users interact with the search results (usage analytics). Analytics Processing Component improves the search relevance and creates search reports with these information. The results from this analysis is send to Content Processing Component to include in the Search Index. This information on usage analytics is stored in Analytics Reporting DB. The Link DB stores information extracted from Content Processing Component. It stores data about search clicks and search results. This information is stored unprocessed. The Analytics Processing Component does the analysis.


    Go to Central Admin à Application Management àService Applications à Manage Service Applications à New(Search Service Application) àFill Mandatory fields and click Ok.


    Goto Central Admin à Application Management àService Applications à Manage Service Applications à Service Application, which we created and click on Ribbon and give the administrator Permissions to the service application


    Now Click on Particular Search Service Application, Which we created (Ex: Sample Search1 )



    Now open the new search service application instance to configure the content source.

    The following figure can explain for you about the search administration, here the searchable content is zero and the default content access account is Search_admin with the privilege to read the content from the local SharePoint site


    Next I will add a content source to the search service application, so in the left quick launch bar you can see the content source in the crawling category by clicking. You can see that in the following window.


    Just click the existing content source and add the URL of the web applications that you need to crawl the content of


    Click Crawl Rule at Left side Panel à Click New Crawl Rule



    then click ok, Then go to content source and full crawl the content source, if we are doing the the first time crawling. From next time onwards we can do Incremental crawl, if we do any changes.

    Now go to particular site collection to search the content. 



    By the above image, we can see the search content

    Some of the Search Query Rules
    The final new search feature of SharePoint 2013 we will cover are Query Rules. The Query Rule has replaced and deprecated the search keywords and best bets functionality of SharePoint 2010. Query Rules can enable a single user search request to trigger multiple queries and return multiple Results sets.
    The components of a Query Rule are:
    ·   Query Condition
    Defines the context in which the query becomes active, such as when a query:
    o   Contains a specific word or words.
    o   Contains a word that is specific to a dictionary.
    o   Contains an action word that matches a specific phrase or term set.
    o   Is common in a different source.
    o   Results include a common result type.
    ·   Query Action
    Defines actions that should occur when a condition is met, such as:
    o   Assigning a promoted result (similar to a Best Bet in SharePoint 2010.)
    o   Creating and displaying a result block.
    o   Changing the ranking of the returned results.
    ·   Publishing Option
    Decides when a query is used. This is particularly useful in commerce sites because the publishing options can set a time period on when a rule is available, such as special offer events or sales. 

    Monday, April 13, 2015

    Administering SharePoint with Windows PowerShell-commands

    Commands:
    PowerShell is powered by commands. Commands get things done. There are four basic types of commands:
    1. cmdlets
    2. functions
    3. scripts 
    4. native commands.

    Cmdlets:
                     Cmdlets (pronounced command-lets) are compiled commands that are installed and registered with PowerShell; they are all named using a verb-noun combination. To make them easy to remember, the noun part of a PowerShell cmdlet is always singular. The verb portion of the name should be one of the PowerShell acceptable verbs. 
                             As you might have already guessed, the SharePoint commands that we will be using are cmdlets. You saw that SharePoint installed the cmdlets on the server, and the Management Shell registered them with the host using the PSC1 file; and you now know how to manually register them in the ISE. You can also create custom cmdlets, but that is a topic beyond the scope of this book. To learn more about writing your own cmdlets, see the MSDN article at http://msdn.microsoft.com/en-us/library/dd878294(VS.85).aspx.

    Functions:
                               Functions are made up of a command or a series of commands that are intended to be reusable for performing a task multiple times within the same script. Functions can accept parameters (variables that are passed to the function at the time the function is called), which enables the same code to be executed with different parameters each time. This provides the benefit of reducing the amount of duplicate code in a script. Functions are defined in PowerShell by typing the function into the host. PowerShell then parses the function and verifies the syntax. Functions can be reused for the lifetime of the host session. If you close the host then you lose the function, and you will need to enter it again when you start another session with the host. You can enter functions into your profile so they will be available whenever you start a session.

    Scripts
                                 PowerShell scripts are made up of a mix of commands, functions, loops, decision trees, user input/output — basically all the methods available to PowerShell for creating reusable code with program like functionality. General SharePoint administration will commonly result in the use of “oneliners,” whereas scripts are generally reserved for larger-scale repetitive tasks, such as an automated installer for SharePoint. Aside from the amount of code involved, a primary difference between a "script" and a "one-liner" is that scripts are saved to a text file with a .PS1 file extension. Later you can run the script by typing in the filename.
    Another great benefit of the script is that once a script is created and tested, it can be saved to a script library and reused. By default, hosts do not run unsigned scripts. This is to protect you from accidentally running scripts that have the same name as common commands. In addition, hosts will warn you if you attempt to run a script that has not been signed. This prevents you from executing a script that has been modified to do something malicious. You can modify the security setting using the cmdlet Set-ExecutionPolicy. Because you can accomplish so much using the SharePoint cmdlets, Scripts are only necessary if you want to chain together a complicated series of cmdlets or walk through complicated loops.

    Native Commands
                                       Native commands are commands that run outside of the host process, such as "notepad.exe" or "stsadm.exe". These commands can still be called from within the commands or scripts that you can execute in the PowerShell host. This provides useful functionality that may not be provided by PowerShell directly. For example, suppose your script were logging information to a .txt file, and at the end of the execution you wanted to display that .txt file automatically. You could add a line such as the following to the end of your script to automatically launch Notepad.exe in its own process and display your log file:

    Notepad.exe "MyLog.txt"


    Listing the SharePoint Commands
                                      The toughest part of using a command-line interface, whether it’s PowerShell, the old Windows CMD prompt, or a Linux bash shell, is determining which commands you can use. PowerShell provides the Get-Command cmdlet to retrieve a list of available commands. Used in isolation, the Get-Command cmdlet will return all commands that are known to the host. Get-Command, like many commands, accepts optional parameters. Because we are interested in only the SharePoint 2013 commands, we can limit the commands displayed to just the SharePoint 2013 commands by using the optional -Module parameter. To list only SharePoint commands, execute the
    following command:
    Get-Command -Module Microsoft.SharePoint.PowerShell
    Below Figure displays the output of the Get-Command cmdlet using the –Module parameter.


    We mentioned earlier that all PowerShell cmdlets consist of a verb and a noun. All the nouns in the SharePoint PowerShell cmdlets start with “SP.” The Get-Command cmdlet accepts wildcards, which you can use to get a list of all the SharePoint PowerShell cmdlets in an easier-to-remember method:
    Get-Command -noun sp*
    As the preceding example demonstrates, you can filter the list somewhat by using the optional -noun or -verb parameter for Get-Command. For example, if you were wondering what commands work with a web application, use the following command:
    Get-Command –Module Microsoft.SharePoint.PowerShell –noun SPWebApp*
    Because the SharePoint module is the only module with cmdlets using the SPWebApplication noun,
    Command to use for backups, use the following
    Get-Command –Module Microsoft.SharePoint.PowerShell –verb Backup