Tuesday, 27 December 2011

PowerShell - Script Comments

Within PowerShell their are two different types of comments:  Inline comments and Block comments.

Inline – #

Inline comments are denoted by a # symbol at the start of the line.  This comment only affects a single line.

Block – <#…#>

Block comments are opened using <# and closed using #> these comments can span multiple lines.

SharePoint 2010 - PowerShell Content Database Backup

“This post details the steps for backing up the content database of a SharePoint site through PowerShell.  Click here to view the steps for backing up a content database through Central Administration.”

PowerShell provides a means to backup data within SharePoint through the following command:

Backup-SPFarm -Directory [Path] -BackupMethod [Full|Differential] -Item [BackupItem] -Verbose -Percentage [Percentage]

Further information on each of the parameters in this command are outlined bellow.

Directory

The Directory parameters specifies the path where the backup will be generated.  This can either be a UNC path or a location on the server.   “You don’t need to enter the spbr* folder name as this will be auto generated”

BackupMethod

The backup method parameter details the type of backup that will be performed.  This can either be Full or Differential:

  • Full - backs up the selected content with all history
  • Differential - backs up all changes to the selected content since the last full backup
  • Item

    The item parameter specifies the component within the farm that will be backed up.  If the item has a unique name you can use just that, however, if it doesn’t then you will need to us the path to the item within the farm.

    In order to get the path to the item you can use the following command:

    Backup-SPFarm -ShowTree

    This will list the tree structure of items within the farm.  In my experience the path to a content database within the farm is in the following format:

    “Farm\Microsoft SharePoint Foundation Web Application\[Site Name]\[Content Database Name]”

    Verbos

    This parameter is optional.  The verbose parameter provides more information about the operation being run.

    Percentage

    This parameter is optional.  The percentage parameter can be used to report progress about the operation at defined percentage intervals.

    SharePoint 2010 - Central Administration Content Database Backup

    “This post details the steps for backing up the content database of a SharePoint site through Central Administration.  Click here to view the steps for backing up a content database through PowerShell.”

    Step 1

    Within Central Administration within the Backup and Restore section click on Perform a backup

    Perform a backup

    Step 2

    Next you need to select the component that you wish to backup.

    Select backup components

    Select the component you want to backup and click Next

    Step 3

    The next step in the backup process allows you to choose the type of the backup and its location.

    A backup can be either Full or Differential

    • Full - backs up the selected content with all history
    • Differential - backs up all changes to the selected content since the last full backup

    The backup file location can either be a UNC path or location on the server, however,  the process running the backup will need to access to write to this location.

    Backup Details

    Once the details of the backup have been entered click Start Backup

    STEP 4

    When the backup is running the following screen will be displayed indicating that backup is currently in progress.

    Backup - Running

    STEP 5

    When the backup has finished running the following screen will be displayed indication the status of the backup components.

    Backup - Status

    Friday, 9 December 2011

    SharePoint 2010 - Timer job not updating after re-deployment

    When deploying a change to an existing timer job you need to restart the SharePoint Timer Job (owstimer.exe) service before the changes will be applied.

    This can be achieved through:

    net stop SPTimerV4
    net start SPTimerV4

     

    Note

    In my experience you need to restart the time job service on each web front end.

    Wednesday, 7 December 2011

    SharePoint 2010 - PowerShell + IntelliSense = PowerGUI

    I recently came across a tool that makes authoring PowerShell scripts easier PowerGUI.

    PowerGUI and its in-built intellisense allows you to browse through the different PowerShell commands and unlock the power of PowerShell to automate administrative tasks and quickly change objects within the SharePoint API.

    You can download it from here

    Once you have downloaded and installed the program you need to load in the Microsoft.SharePoint.PowerShell library snapin.

    Step 1

    Within PowerGUI Click on File then PowerShell Libraries

    1 - Powershell Libraries

    STEP 2

    In the Snapins/Modules window Select the Microsoft.SharePoint.PowerShell library and Click OK

    2 - Snapins

    STEP 3

    You are now ready to start using the SharePoint PowerShell library.  Click New File

    3 - New File

    STEP 4

    Within the PowerGUI code editor when you type you should know have IntelliSense on the different SharePoint - PowerShell commands.

    4 - Intellisence

    STEP 5

    Once you have created your new script you can run it by clicking on the Start icon

    5 - Run Script

    STEP 6

    The output from your script will know be output in the console window.

    6 - Script Output

    Tuesday, 6 December 2011

    SharePoint 2010 - ViewFormPagesLockdown

    Within an anonymous access SharePoint site you may wish to prevent users from navigating to the underlying lists e.g:

    • /_layouts/viewlsts.aspx
    • /Lists/[ListName]/AlItems.aspx

    This can be achieved by activating the ViewFormPagesLockdown feature.  This is a hidden feature, however, you can access it through PowerShell.

    Get-SPFeature | where { $_.DisplayName -eq "ViewFormPagesLockdown"}

    This will display:

    1 - ViewFormPagesLockdownThis tells us that the feature is scoped at the site collection level as well as the features ID.  The feature can then be activated using PowerShell similar to bellow:

    Enable-SPFeature -url http://sharepoint -identity 7c637b23-06c4-4724-9a9a-7c175762c5c4 -confirm:$false


    Anonymous users will now need to authenticate in order to view the underlying SharePoint lists and libraries.


    Note


    “As this feature is activated across a site collection this can lead to issues with anonymous users posting comments on blogs etc.. However the following blog details a method for overcoming this.”

    Monday, 5 December 2011

    SharePoint 2010 - Enable Anonymous Access

    When creating an external facing SharePoint site you are probably going to have to configure anonymous access to allow users to view your site.

    You can achieve this by following these steps:

    Step 1

    Within central administration Click on Application Management then Manage web applications.

    1 - Application Management

    STEP 2

    Select the web application that you want to configure anonymous access for and Click on Authentication Providers.

    2 - Web Applications

    STEP 3

    Within the Authentication Providers window Click Default

    3 - Authentication Providers

    STEP 4

    Within the Edit Authentication window scroll down and Select the Enable anonymous access checkbox.  Then Click Save.

    4 - Edit Authentication

    STEP 5

    After editing the authentication Select the desired web application and Click Anonymous Policy

    5 - Web Applications

    STEP 6

    Within the Anonymous Access Restrictions window select None – no policy then Click Save

    6 - Anonymous Access Restrictions

    Step 7

    Within the web site you have configured anonymous authentication on navigate to Site Permissions

    You can achieve this through Site Actions – Site Permissions

    7 - Site Permissions

    STEP 8

    Within Site Permissions Click Anonymous Access.

    8 - Anonymous Access

    STEP 9

    Within the Anonymous Access window you can specify what items have anonymous access.  Select Entire Web site then click OK.

    9 - Anonymous Access (2)

    STEP 10

    Anonymous access should now be configured and your site permissions should display something similar to the following:

    10 - Site Permissions

    Note

    “After enabling anonymous access you may wish to prevent anonymous users from accessing the underlying SharePoint lists and libraries e.g:

    • /_layouts/viewlsts.aspx
    • /Lists/[ListName]/AlItems.aspx

    The can be achieved through the ViewFormPagesLockdown feature.  Click here for details on how to configure this.”