Tag Archives: admin

Scripting your SharePoint Farm Backup with PowerShell in Task Scheduler

Hi guys,

Today, I would like to share one of the SharePoint admin must-do deployment steps which is to configure a task scheduler and to backup your SharePoint Farm. Note that this is working for both 2010 and 2013 environment.

Also, I’m leveraging this SP Farm Backup script created by good people (thanks for making this powerful and useful script). Please ensure that you have downloaded them and configure the params.xml file base on your corporate needs.

For the interest of those who want to just reference my configuration, below are the xml I used for my SharePoint Farm

<?xml version="1.0" encoding="utf-8"?>
<backup version="2.3">
 <backupserver>SERVER_HOST_NAME</backupserver> <!-- Name of server if backup share is on remote server -->
 <sendemail>TRUE</sendemail> <!-- Option: TRUE/FALSE -->
 <environment>My SharePoint (Staging)</environment>
 <emailto>yihaa_5@hotmail.com</emailto> <!-- Multiple recipients must be comma separated -->
 <emailcc></emailcc> <!-- Multiple recipients must be comma separated -->
 <backupwebconfigonly>FALSE</backupwebconfigonly> <!-- IMPORTANT: If set to TRUE then web.config is backed up and NOT Virtual Directories -->
 <exportsolutions>TRUE</exportsolutions> <!-- Option: TRUE/FALSE -->
 <backupiis>TRUE</backupiis> <!-- Option: TRUE/FALSE -->
 <backupgac>TRUE</backupgac> <!-- Option: TRUE/FALSE -->
 <backupulslogs>TRUE</backupulslogs> <!-- Option: TRUE/FALSE -->
 <backup14hive>FALSE</backup14hive> <!-- Option: TRUE/FALSE -->
 <backupfulldays>Sunday</backupfulldays> <!-- Used in conjunction with option 1 of backupoption - Days must be comma separated -->
 <backupthreads>1</backupthreads> <!-- Option: 1 to 10 -->
 <backupsites>TRUE</backupsites> <!-- Option: TRUE/FALSE -->
 <includemysites>FALSE</includemysites> <!-- Option: TRUE/FALSE -->
 <backupconfigonly>FALSE</backupconfigonly> <!-- Option: TRUE/FALSE -->
 <backupoption>0</backupoption> <!-- Option: 0/1/2 -->
 <daystoretain>30</daystoretain> <!-- No. of days backups to retain (Must be greater than 1 day. Default: 7 days)-->

The key consideration of the above configuration is on the number of days to retain (daystoretain). You would need to really consult your technical manager in order to craft out the backup data retention period.

Once you have the SP Farm Backup script ready,  create a text file name “CreateTaskSchedulerForSPBackup” and subsequently change the extension to “.ps1” file (PowerShell extension).

Copy the below PowerShell script into the newly created CreateTaskSchedulerForSPBackup PowerShell

$A = New-ScheduledTaskAction -Execute "F:\TaskScheduler\Farm-Backup.bat" -WorkingDirectory "F:\TaskScheduler\"
$T = New-ScheduledTaskTrigger -Daily -DaysInterval 1 -At (Get-Date).Date
$S = New-ScheduledTaskSettingsSet

Register-ScheduledTask -Action $A -User "$($env:USERDOMAIN)\spfarmadmin" -Trigger $T -Settings $S -Force -TaskName "SharePoint Farm Backup" -RunLevel 1 -Password "xxxxxxxx"

For above PowerShell, there are certain things that you need to change based on your environment.

Farm-Backup.bat Path

It is assuming that you have copied all the SP Farm Backup downloaded script (together with your params.xml) into F:\TaskScheduler\ Folder of the server running the task scheduler. You only need to configure Task Scheduler in 1 of your SharePoint server only.

Task User Account

For most of the environment, your SP Farm Admin account is not always the local admin account where you access the server and create the task schedule. You will have to explicitly specify the Farm Admin account in the PowerShell as well as the Password of this account so that when the task is running, it takes in the Farm Admin account to perform Backup.

You need to use Farm Admin account to execute the backup script. Else you will hit access denied during the backup job.

Note that your password is entered in plain text. If you wish not to dispose the Password in Script. You can refer to last section on how to do it.

Backup Directory

It is also assume that you have created a Shared Folder in the server where you want to store the backup files. It must be a Network Shared Folder. In my example, it will be in “\\SERVER_HOST_NAME\FarmBackup” . 

Few things you need to consider when creating this shared folder:

  • Central Admin app pool account must have read/write access to the location of the backups.
  • SQL Service account must have read/write access to the location of the backups.
  • When running a farm backup from STSADM or Windows PowerShell, the account you’re running it as must have read/write access the location of the backups.
  • The location must be accessible from the SharePoint machine the backup is running on.
  • The location must be accessible from the SQL instance that SharePoint is trying to back up.

automated task scheduler for SharePoint Backup

Now that you have the script, kindly open PowerShell with Administrator rights in the server where you want to create the Task Scheduler.

Run the CreateTaskSchedulerForSPBackup.ps1

To double check if the task is created successfully, you go to Task Scheduler (taskschd) and check. The task “SharePoint Farm Backup” will be created.

automated task scheduler for SharePoint Backup output

How to avoid storing password into PowerShell Script.

As mentioned just now, you may want to avoid storing your password into the PowerShell Script.

In order to do that, you can use the PowerShell Script below to archive that.

$password = Read-Host -AsSecureString "Enter your password and hit Enter"
$bstr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)
$plainPassword = [RunTime.InteropServices.Marshal]::PtrToStringAuto($bstr)

Register-ScheduledTask -Action $A -User "$($env:USERDOMAIN)\spfarmadmin" -Trigger $T -Settings $S -Force -TaskName "SharePoint Farm Backup" -RunLevel 1 -Password $plainPassword

Save the CreateTaskSchedulerForSPBackup.ps1 and reruns it via PowerShell.

I hope the script to create task schedule can save you some time. It happens to me that manually creating Task Scheduler can be very error prone as there are many clicking in the Task Scheduler UI, repeating the same creation steps in difference farm environment can be very tedious too.

PowerShell script to test SharePoint Send Mail

Thought it would be good to share some of my script to the public

Copy the below script and save as .ps1 file. Run it in SharePoint Management Shell with Admin Rights.

$webUrl = Read-Host "Enter SharePoint Web Url, e.g. https://sharepoint.com"

$web = Get-SPWeb $webUrl;

 $header = New-Object System.Collections.Specialized.StringDictionary
 $to = Read-Host "Enter Email TO address (e.g. abc@def.com) "
 $subject = Read-Host "Enter Email Subject "

$body = Read-Host "Enter Email Body Content "
 $sent = [Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($web,$header,$body);
 Write-Host -f Green "Email ($to) Sent successfully"
 Write-Host -f Red "Email failed to send"

Exception trying get context compatibility level: System.IO.FileNotFoundException

Bump into this error when hitting my SharePoint 2013 Web Application.

HTTP/1.1 200 OK Server: Microsoft-IIS/7.5 Date: <DATE TIME> GMT Connection: close

Exception trying get context compatibility level: System.IO.FileNotFoundException: The site <URL> could not be found in the Web application SPWebApplication Name=<WEB_APP_NAME>.
 at Microsoft.SharePoint.SPSite.LookupSiteInfo(SPFarm farm, Boolean contextSite, Boolean swapSchemeForPathBasedSites, Uri& requestUri, Boolean& lookupRequiredContext, Guid& applicationId, Guid& contentDatabaseId, Guid& siteId, Guid& siteSubscriptionId, SPUrlZone& zone, String& serverRelativeUrl, Boolean& hostHeaderIsSiteName, Boolean& appWebRequest, String& appHostHeaderRedirectDomain, String& appSiteDomainPrefix, String& subscriptionName, String& appSiteDomainId, Uri& primaryUri)
 at Microsoft.SharePoint.ApplicationRuntime.SPRequestModule.GetContextCompatibilityLevel(Uri requestUri)

Subsequently, i tried to run powershell Get-SPSite <url>

Get-SPSite : Cannot find an SPSite object with Id or Url : xxxx

Tried to go to central admin and view all site collections. Amazingly, there is no Site Collection attached to the Web Application.  The site collection was GONE by no reason…

Steps to Recover the Site Collection

  1. Run the following Powershell.
    $tempSite = Get-SPDeletedSite
  2. That simple…

Setting up a Single-box SharePoint 2013 Virtual Machine.

First thing first, below are some files which you would need in order to setup your own SP2013 Environment. VMware Workstation 9 – here SharePoint 2013 – here SQL 2012 – here Windows 2012 Server – here Visual Studio 2012 – here Here we go.

VMWare Workstation

  1. Install VMWare Workstation on to your local PC, Ensure that your local PC has got at least 8 gb RAM. You would need to allocate some of the RAM to your 2012 server later.
  2. Once completed the Workstation installation (i would not go through how you install software as it is simple), create a “New virtual machine“, choose Typical installation, PLEASE select option “I will install the operating system later“, else you will encounter error later. Then click Next until the vm files are created in your document folder “Documents\Virtual Machines\Windows Server 2012”
  3. Before powering up your vm, please map your Windows Server 2012 ISO file to boot up and install.

Windows Server 2012

  1. There is nothing much crucial to explain here. Just follow the setup wizard.
  2. Once completed, you will be asked to enter the administrator password bla bla bla.
  3. Remember to rename your windows name to something meaningful.. NOT Something like win-is2xx92243d which is totally making no sense. To configure this, go to Server Manager > Local Server > Click Computer Name > Change > Rename your server and click OK.Configure Windows 2012 Computer Name
  4. Restart your computer.
  5. Next, it is always good to set your Server IP address. Though this is not actually required for a Single Box Setup. But good to learn? =) Configure Server IP Windows 2012 1 then Configure Server IP Windows 2012 2
  6. Next is to setup Active Director Domain Services (AD DS), this is required for you to create services account for sharepoint and sql later on. Note! dcpromo.exe is deprecated for windows 2012. Sadly.
  7. Kindly go to Server Manager > Dashboard > Add Roles and Features
  8. Select Role-based or Feature-based installation
  9. Select your server from the Server Pool list and click “Next”
  10. Check on “Active Director Domain Services” check box, a prompt up will be displayed. Click “Add Feature”.
  11. Now, click NEXT all the way down until the installation completed.

Promote Windows 2012 to a Domain Controller

  1. Once your server 2012 is installed with AD DS, you have to promote your server to a domain controller.
  2. In the Server Manager, you may notice this Alert icon. Click on it and click on “promote this server to a domain controller”. Configure Domain Controller Windows 2012 1
  3. In the “Active Director Domain Services Configuration Wizard”, Select Add a new forest, put your favorite name. Configure Domain Controller Windows 2012 1
  4. Click Next, leave the rest default and specify your DSRM Password Configure Domain Controller Windows 2012 2
  5. Click Next all the way down until you see “Install” button. Kindly ignore those warning message. Click Install. Reboot and  you are done with DC Promo.

Service Account

  1. Now that your DC is up, you would need FEW accounts to setup your SharePoint 2013 environment. Note that i did not mention how many account required, because, ultimately, it depends on how segregated you want your farm to be. For Single Box solution and Less Error Prone. You may only need 3 accounts.
    1. Setup user account
    2. Server farm account or database access account
    3. SQL Server service account.
  2. Refer here  and here for the detail account.
  3. Open Run (Windows + R) then enter “dsa.msc” to open Active Director Users and Computers.
  4. Right Click  your Domain and add a new OU (this is my usual practice to park my sp account into an OU) Configure Service Account 1
  5. Add those 3 accounts.
    • spsetup
    • spfarm
    • sqlservice

SQL 2012

  1. Map your “SQLServer2012SP1-FullSlipstream-ENU-x64.iso” file to vm
  2. Run the ISO file in your VM, Select Installation Tab on the left and click New SQL Server stand-alone installation or add features to an existing installation.
  3. Click OK after the Setup Support Rules is completed, enter your product key (if you don’t have, use evaluation =D ), click OK. Include SQL Product Updates. Click OK~ These are pretty boring. Configure SQL 2012 2
  4. Next, select Role Mode. For evaluation purpose, i select All features with default.
  5. Name your SQL Instance
  6. Specify your services account. In my case, i use “SQL Server service account” that i have created previously. Configure SQL 2012 4
  7. Specify the Admin Account using the same SQL Server service account. account. (Well, this is for evaluation, you can still opt to use other account) Configure SQL 2012 5
  8. Analysis Configuration – Specify the same service account.
  9. Distributed Replay Controller – Specify the same service account and the Controller Name as your Server Name
  10. Click NEXT, NEXT, NEXT to install.. go get a coffee and come back after 30 mins…
  11. ..
  12. OK~ Next thing is to setup permission for SharePoint Setup Account. Base on the article above. You have to grant the account (In my case “spsetup”) DBCreator and SecurityAdmin permission.
  13. At this time, your server only allow Windows Authentication mode to access to your Database Engine. Please kindly Grant the SQLService account with Local Administrator right temporary. Log Off and switch to this account.
  14. Open your SQL Management Studio, Login via Windows Authentication, Right click on the “Login” node and “New Login”
    Configure SQL 2012 5.5
  15. Select the SharePoint Setup Account “spsetup” and go to Server Roles. Check the 2 server roles “dbcreator” and “securityadmin”
    Configure SQL 2012 6
  16. Click OK to proceed.
  17. For SharePoint 2013, there is one additional step is to change the Max Degree of parallelism to 1. Go to Database Engine, Right Click and Select Property. Under Advanced panel. Change the value to 1.
    Configure SQL 2012 7
  18. Click OK to proceed. Once this is completed, you may Switch User back to SharePoint Setup Account now (via Alt + Del + Insert) Note: Remove the SQLService account from local admin group once you are done with setting up the permissions.

SharePoint 2013

  1. Map your SP2013 iso file to your virtual machine (if you haven’t)
  2. Go into your vm and install SP2013 pre-requisites. The next few steps are for Offline Pre-requisite installation.
  3. Run Powershell with Administrator rights. Ensure you have executed the following command before Set-ExecutionPolicy RemoteSigned
  4. Run the following command. Make sure the path is where you store the pre-requisite files. Also, copy the “prerequisiteinstaller.exe” from your SP2013 iso to the same folder where your script is located.
    $SharePoint2013Path = "C:\Prerequisite"
    Start-Process "$SharePoint2013Path\PrerequisiteInstaller.exe" –ArgumentList "/SQLNCli:$SharePoint2013Path\PrerequisiteInstallerFiles\sqlncli.msi /IDFX:$SharePoint2013Path\PrerequisiteInstallerFiles\Windows6.1-KB974405-x64.msu /IDFX11:$SharePoint2013Path\PrerequisiteInstallerFiles\MicrosoftIdentityExtensions-64.msi /Sync:$SharePoint2013Path\PrerequisiteInstallerFiles\Synchronization.msi /AppFabric:$SharePoint2013Path\PrerequisiteInstallerFiles\WindowsServerAppFabricSetup_x64.exe /KB2671763:$SharePoint2013Path\PrerequisiteInstallerFiles\AppFabric1.1-RTM-KB2671763-x64-ENU.exe /MSIPCClient:$SharePoint2013Path\PrerequisiteInstallerFiles\setup_msipc_x64.msi /WCFDataServices:$SharePoint2013Path\PrerequisiteInstallerFiles\WcfDataServices.exe"
  5. After running the script, i encountered the following error “The tool was unable to install Application Server Role, Web Server (IIS) Role
  6. After 2 rounds of rebooting. The pre-requisite installation is finally done.
  7. Open the SharePoint Installer Splash Screen and hit Install SharePoint Server.
  8. Put in the Evaluation Product Key. NQTMW-K63MQ-39G6H-B2CH9-FRDWJ
  9. Click Next  until the installation is completed (yawn..)
  10. Once the installation is completed, leave the check box default “Run SharePoint Products Configuration Wizard”. Close your installation wizard.
  11. In the SharePoint Configuration Wizard, click Next.
  12. System will prompt you to stop the 3 services account, IIS, SP Admin Service, SP Timer Service, click Yes to continue.
  13. Select “Create a new server farm” and click OK.
  14. At this point, you may want to setup an ALIAS for SQL connection. (Good practice!)
  15. Fire Up “Run” and enter “cliconfg”.
  16. Under Alias tab, enter “sql” name and select “TCP/IP” and your sql server name (basically the same server since we are setting up a single box server.)
    Configure SharePoint 1
  17. Click OK and exit the CliConfg.
  18. Back to the SharePoint Product Configuration Wizard, enter the ALIAS that you just created as the SQL name.
  19. Next, specify the Login ID for “Server farm account or database access account” created earlier. (In my case “spfarm”).
    Configure SharePoint 2
  20. Specify the passphrase and click Next
  21. Specify the Central Admin port number and the authentication mode. Use NTLM for simplicity.
    Configure SharePoint 3
  22. Click Next to start configuring. Again you can go get some drink and come back like 20 mins time
  23. Tada~
    Configure SharePoint 4
  24. If you open your Task Manager, you will noticed that there is one new windows services running “AppFabric Service” which took you 300++mb of RAM. You may actually reduce the RAM usage to make room for other services. Refer here on how to reduce the AppFabric Memory Usage
  25. Once you close the Product Configuration Wizard, IE will be fired up to performance Configuration. Select all services if you like. Also, you may use a separate service account for the services that you intend to add. I would not recommend turning on Search Service Application as this will take up A LOT OF YOUR MEMORY!!!! Please note. Do it only if you have a lot of RAM in your VM Host.
  26. The Configuration may take quite some time. It happened to me before that it stuck forever. In case the screen doesn’t refresh or whatsoever, try to open the Central Admin again. The Services will still be created at the backend.

Configure SharePoint 5

Create Site Collection

  1. Once the Central Admin is done, you may proceed to create a Site Collection for your primary Web Application – 80
  2. Click on “Create Site Collection” under Application Management tab.
  3. Ensure the Web Application is selected correctly. Put in the Name and select your Site Template
    Configure SharePoint 6
  4. Specify the Primary Site Collection Admin – AHCHENG\spsetup
  5. Click OK!!! and Welcome to SharePoint 2013!


Note: If Newsfeed or MySite is having this “We’re almost ready!” error, please kindly check here to add your server as part of cache cluster

How to grant Local Administrator rights

The following steps show you how to grant a domain user or local user with Local Administrator rights.
  1. Logon to the machine/server that you want to grant Local Administrator right to.
  2. Open “Run” from the Start Menu. Or alternatively hit [Windows + R] key
  3. enter “dsa.msc” (if you are in a Domain Controller machine) or “lusrmgr.msc” (for any other machine)
  4. Navigate to your domain (if DC) and then to “Built in”
  5. Double click on the Administrator group.
  6. Go to “Members” tab and click “Add” button
  7. Assign the account that you want to grant access with.
  8. Click Ok to complete

How to Assign Local Administrator Right

SharePoint 2013 – Analytics Feature

For some reasons, Web Analytics in SharePoint 2010 is going to be entirely revamped. Microsoft shared that the Web Analytic in 2010 is with the following drawbacks.

  1. There was no concept of item to item recommendations based on user behavior. i.e. people who viewed this also viewed other
  2. Couldn’t promote search results based on an item’s popularity as determined by Number of items an item was viewed.
  3. It required a ver powerful SQL box and significant storage and IO
  4. Lists don’t have explicit view counts (Though you can rough estimate it via the default url of the default list view)
  5. Architecture could have problems scaling to large numbers

That is a bad and good news.

The bad news is, for any existing application that leveraged on Web Analytic requires re-development. So please test your application before upgrading from 2010 to 2013.

The good news is, Web Analytic sucks! Many people have been complaining on the usability of web analytic in technical point of view. Things like manual triggering of web analytic stats is not possible, page view is not being updated and always show 0 and many more.

Analytic System (2013)

It is now possible to find relevant information such as relevancy for search results. the analytics provide view and click through rate as well as what’s popular content based on number of view and unique view.

The model is extensible for 3rd parties to build into the platform.. hmmm

The new analytics system are additionally enhanced to allow filtering and normalisation. Things like Special Handling  where certain type of events will be directly written to the usage file. Some events like those from robots, should not be counted (Filtered Out). Rewrite the log so it can be counted along with other hit types e.g. document reads through the WAC should be counted as reads against the document.

You may now configure up to 12 custom events in addition to what comes OOB. We may also calculate the sum or average across events.

By default, a series of reports are available (like in Web Analytics) – Yawn…

Below is the list of reports provided in 2013

  1. Usage Report
  2. Number of Queries
  3. Top Queries by Day
  4. Top Queries by Month
  5. Abandoned Queries by Day (search that received low click-through)
  6. Abandoned Queries by Month
  7. No Result Queries by Day
  8. No Result Queries by Month
  9. Query Rule Usage by Day (how often query rules fire and etc.)
  10. Query Rule Usage by Month

SharePoint 2013 – Request Manager (New!)

This is a new feature in SharePoint 2013 to control routing and throttling of your SharePoint. Thing you can do is to check the incoming url, specify your rules on how to handle the request. Unlikely Throttling in SharePoint 2010, where you can only specify what is the maximum number of list item to be displayed (For example)

Another example is to deny requests from agent with “Microsoft Office OneNOte 2010”. Additionally, you can specify the expiration of rule or to use a health score threshold to activate it. (Interesting…)

Routing Weights (aka Load Balancing) is a form of control to servicing WFEs. More powerful WFE can be associated with lower static weight (0 being the lowest) and therefore will get the most requests. Another weight which is health weight is updated by Policy Engine (SharePoint). This weight can be used for routing rules as well.

SharePoint 2013 – Introduction and overview

Just to make an overview of SharePoint 2013

  1. Major changes on UE. More AJAX is incorporated. Things like Site Setting. No more Traditional Page Refresh.
  2. Office Web Apps is no longer a service application. That means, the installing of Web Officer Apps is separated and can be shared for Lynch and Exchange.
  3. eDiscovery capabilities, support for searching and exporting content from file shares, exchange and SharePoint. Team folder can be extract and shared via Exchange.
  4. Web Analytic is now part of the search. Click through rate is integrated to enhance the preciseness of search. Things it tracks is like People who view this item also view other item.
  5. SharePoint theme is now based on HTML. Designer can make use of this HTML and render back  to MasterPage and etc.Additionally, SharePoint 15 provides “Tri it Out” feature which you can see how the new theme looks. Note: PowerPoint is no longer used to create custom theme.
  6. Web Part is now rendered using DIV! no more TABLE =)
  7. SEO friendly. In term of SharePoint URLs.
  8. Feed is enhanced to allow user participating, like putting # tag. Design for My Site is much more simplified now.
  9. Search. Personalized search results based on search history. Previously searched Content will be promoted. Previewing of content is enhanced as well.
  10. Excel BI. Instant analysis through in Memory BI engine.
  11. Excel Services. Improved data exploration. User can easily explore data or report. User can point the value in chart or pivot table. Comments for drill down is supported. Calculated measures and members.
  12. Performance Point Services
    1. Enhanced Filter and search
    2. Dashboard Migration. Dashboard can now be exported from server to server!! User can create the dash in Staging Environment and then exported to Production.
  13. Visio Services is now allow more data sources. Comments on Visio drawing can be added directly to the file for discussion =)
  14. Mobile Agent auto redirection can be turn on/off. (SharePoint 2010 will always redirect user to Mobile view first … and this feature is not really useful, personally)
  15. Services does not compromise performance of SharePoint. As they are not actually sit inside SharePoint now. They are patched outside of SharePoint.
  16. Major enhancement for Request Permission feature in SharePoint 15. Previously, user can only request access to the site collection admin. They couldn’t request on someone’s behalf, they couldn’t check the request status as well as all the sent requests. With SharePoint 15, the user is now able to send Any Permission Type (including those that the request current’t does not own) request to site collection admin. Also, the requester is able to view the existing users who is also with the same permission and etc. Admin would then be able to response the request with comment in conversional manner.