Posts

Showing posts from April, 2014

Make SQL Server write its own scripts

Make SQL Server write your scripts for you! Say you want to create a T-SQL script to backup every database on your SQL Server and there are over 100. You can obtain a list of all your databases with the following command: SELECT NAME FROM sys.databases That lists all databases on that SQL server.  You can also add literal text in your query. This is a valid query: SELECT 'Do not forget to back up database ', NAME FROM sys.databases That gives you two columns, but you could also make it one column with a + instead of a comma SELECT 'Do not forget to back up database ' + NAME FROM sys.databases I went a step further and got this select statement to generate my backup statements SELECT 'BACKUP DATABASE ' + NAME + ' TO DISK = ''C:\' + NAME + '.BAK'' FROM sys.databases Note: Those are all single quotes above. Two single quotes are used to place a single quote (escape character). The output looks like: BACKUP DATABASE ...

InfoPath 2010 get the highest or lowest value from two or more disparate fields using Rules

Image
InfoPath 2010 get the highest or lowest value from two or more disparate fields. I was working on an InfoPath 2010 project where I would pull in the pilot, copilot and crew with the respective hours of flight experience.  Then I needed to know the lowest number because that determined the highest risk factors.  They could then mitigate those risks, but it was important to identify ahead of time the risk factor for the mission. Since the data came from different fields, I could not use the max or min functions built in for a repeating row.  The display requirements also didn't fit repeating table either, so even if I could smush my data into one, I'd have to pull it back out to fit the display requirements. I created a button that executed a series of rules.  There is no IF THEN ELSE for InfoPath 2010 rules, so I needed to use a little trickery and some Algebra.  I had a field named DayRisk1 .  Clicking the button first sets the field to 10,000...

SharePoint 2010 Powershell script to restore a Site Collection from a Backup.

SharePoint 2010 Powershell script to restore a Site Collection Backup Here is my script I wrote to do a restore from a Site Collection Backup. This will create a new content database for the site collection.  It made sense for us to do this because each site collection was a military unit that could be redeployed and they might want to take the database with them. Since I was re-running my script, (and timing the job) I started out by deleting the site collection.  Unless you're doing the same, you will not need this: Get-SPContentDatabase -Identity "WSS_Content_SiteCollection1" | Remove-SPContentDatabase -Confirm:$false Note: That's all one line ^ New-SPContentDatabase -Name "WSS_Content_SiteCollection1" -WebApplication http://sharepoint.name Note: That's also all one line ^ Wait, did I just delete a site collection only to add it back???  Yes I did.  As I was running the restore job multiple times I wanted to be sure the previous attem...

SharePoint 2010 Powershell script to create a Site Collection Backup

SharePoint 2010 Powershell script to create a Site Collection Backup Backup-SPSite -Identity http://sharepoint.name/sitecollection1 -Path \\UNCPATH\to\save\location\sitecollection1.bak This command will make the site collection read only while it runs. In order to leave the site writeable, use the versin below Backup-SPSite -Identity http://sharepoint.name/sitecollection1 -nositelock -Path \\UNCPATH\to\save\location\sitecollection1.bak This can be batched.  Just save the file as a .ps1 file and then open powershell, navigate to the path where the file lives, and type .\filename.ps1 This displays no output though, so I added text output to tell me the time a backup started and when it finished. The finished script is below. $StartDate = Get-Date; "Started SiteCollection1" Backup-SPSite -Identity http://sharepoint.name/sitecollection1 -Path \\UNCPATH\to\save\location\sitecollection1.bak $EndDate = Get-Date; "SiteCollection1: Started at $StartDate and ...

Migrating a fragile SharePoint 2010 farm to new hardware.

When I first became Administrator of the "C" SharePoint 2010 portal (real name classified) I noticed how delicate it was, and how riddled with errors the logfiles were. "You've had some cowboys in here", I thought.  Search was not working.  The search service that was trying to run was calling a database that was missing from SQL server. A previous admin deleted that database from SQL; SharePoint had no idea and was still looking for it. The owner of most of the content databases was the previous admin's elevated account.  Services were running under that account as well.  It was only a matter of time before that account expired and got removed causing the farm to crash. The SharePoint Service accounts were unmanaged and I only had the password to one of them. There was 2.2TB of data in SQL server contained within over 60 site collections and 60 content databases.  Each Site collection got its own content database. The SharePoint servers had nev...

Moving SharePoint 2010 to a new SQL Server

As a part of an Enterprise SharePoint 2010 portal migration to new hardware, I had developed a plan to utilize a new SQL server. I found this article which gives direction to move all databases. http://technet.microsoft.com/en-us/library/cc512723(v=office.14).aspx This one uses a database detach and restore along with a SQL alias to trick SharePoint into thinking it is still pointing to the old server. The database detach and restore method will not work for us as we have over 1TB of data and around 50 databases to move in a small ASI (outage) window. I planned to adapt this by backing up from the old, restoring to new, with the SQL alias to redirect. This is touched on in the technet article, but there's no detailed instruction there. Here was my plan Back up all the sharepoint databases including the sharepoint_config db; Restore them to the new server Add a WFE (web front end) to the current farm (not in the load balancer) Add a SQL Alias to the new SQL serve...

How to set up a SQL Alias for MS SQL Server 2008 R2 (for use with SharePoint 2010)

Image
To setup a SQL Alias, go to c:\windows\system32\ and open Cliconfg.exe from each server including the MSSQL Server and add an alias.  Here you define the OLDSERVER as an alias that redirects to the NEWSERVER.  You will need to repeat this process using CliConfg.exe in the folder c:\windows\syswow64.  This is repetitive, I know, but it's easier to do them both than to debug why one app sees the new server and the other is trying to hit the old one. If you have the good fortune to set up a SharePoint Farm from scratch, you should start out using an alias.  It's good "SQL Hardening" practice, and allows you to easier switch to a new MS SQL Server. Convention says to start with "A-" to indicate that it's an alias, but why be conventional - few people catch on to that convention anyway. Last note: be sure Named Pipes is enabled.  Open the SQL Server Configuration Manager , unfold the node SQL Server Network Configuration and select Protocols for MS...

Obtaining your SharePoint 2010 Product Key from Production

I needed to get the product key from the currently installed Sharepoint 2010 (in production) Take the script below, save it as a .vbs file and run it from one of the farm machines (not the SQL box). I found this script at: http://blog.jamzarwebdesign.com.au/wp-content/uploads/2011/11/SharePoint-2010-License.txt '========================================================================= ' VBScript Source File ' ' AUTHOR: Stewart Brown ' COMPANY: Jamzar Web Design ' WEBSITE: blog.jamzarwebdesign.com.au ' DATE: 4/11/2011 ' COMMENT: Will display the SharePoint 2010 License Key. ' ' Found original code on internet but can't remember where I ' found it so I'm not sure who to thank. ' If you own this code and can prove it, then please leave a ' message on blog and once confirmed I will update this code. '========================================================================= const HKEY_LO...

A system restart from a previous installation or update is pending when installing SharePoint 2010

After installing the prerequisites for SharePoint 2010, I was unable to install SharePoint I tracked down the error to a registry key that was not clearing itself. The fix was to open regedit and find the following entry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager Rename the “ PendingFileRenameOperations ” value to “ PendingFileRenameOperations2 “   That fixed it - no reboot required.

Configure Data Replication in SQL Server 2008 R2

Image
This is a useful process, and it might help with my SharePoint 2010 Migration project. It looks like it may need to be set up one database at a time though, which could make things more involved. Also worthy of note: you must connect via machinename (or alias) but not localhost. In my case the restore method triggered the HBSS system as a possible attack, so this method was abandoned for the moment.

Adventures in SharePoint

My adventures in SharePoint land.  SharePoint has taken me all over from when I picked it up in Columbus, Ohio. I've been in Kuwait for over a year, and now I'm in Afghanistan for nearly a year. The end goal is a lakeside resort I've been building in Ohio ( www.happylake.com )