Get Command-Line Output from SQL Server 2005

Sometimes, from SQL Server you need to execute a command line application and retrieve its output in a variable.

When you want to to this, you have to consider:

  1. Enabling the execution of the xp_cmdshell stored procedure
  2. Saving the output of the command (maybe more lines) in a temporary table
  3. Taking the first row a putting it in a variable

Finally, here is a complete example. In this case I take the first user in Active Directory whose distinguished name starts with Damiano:

EXEC sp_configure 'show advanced options', 1
EXEC sp_configure 'xp_cmdshell', 1
    LINE nvarchar(4000)
INSERT INTO #TEMP EXECUTE master..xp_cmdshell 'dsquery user -name Damiano*'
EXEC sp_configure 'xp_cmdshell', 0
EXEC sp_configure 'show advanced options', 0
DECLARE @MYVAR nvarchar(512)

Setup Kerberos Authentication

Kerberos is used when you have Windows authentication with impersonification and the impersonated user needs to access resources outside the web server.
For example, you can use it when from your SharePoint server you need to access an Exchange web-service to get the user mail and calendar.

To enable Kerberos authentication, you need to complete the following tasks:

  1. From the Central Administration, change the web-application settings to use Kerberos (negotiate) authentication insted of NTLM authentication
  2. To add the SPNs for the web-server, from a command line prompt, execute:
    1. setspn -a HTTP/ServerName Domain\ServerName
    2. setspn -a HTTP/ServerName.Domain Domain\ServerName
  3. To add the SPNs for the application pool user, from a command line prompt, execute:
    1. setspn -a HTTP/ServerName Domain\User
    2. setspn -a HTTP/ServerName.Domain Domain\User
  4. Finally, from the Active Directory Users and Computer, check the application pool user as trusted for delegation.

More details in the article How to configure a Windows SharePoint Services virtual server to use Kerberos authentication and how to switch from Kerberos authentication back to NTLM authentication.

Renaming a SharePoint 2007 Server

Sometimes you have the need to rename a SharePoint server. In my case, it happened when I created a "template" virtual machine and had to "deploy" it to the variour developers involved in the project.

So in the end I wrote the steps necessary to do it:

  1. Change the alternate access mappings
    From the Central Administration, go to Operations | Alternate access mappings
    Change each internal url to point to the new server name
  2. Run stsadm to rename the server
    From a command line prompt, execute:
    1. cd "c:\program files\common files\Microsoft shared\web server extensions\12\bin"
    2. stsadm -o renameserver -oldservername OldServerName -newservername NewServerName
  3. Rename the server, and reboot the computer
    If you are cloning a virtual machine, I reccomend you to use NewSID 4.10 (as it's no more possible to download it from Microsoft website, you can also find a backup copy in the file
  4. Update farm credentials
    From a command line prompt, execute:
    1. cd "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN"
    2. stsadm –o updatefarmcredentials –userlogin "NEWSERVERNAME\SharePointAdministration" –password "NewPassword"

More details in the article Rename a stand-alone server (SharePoint Server 2007).


Welcome to my new web-site!
I'm working on it day by day, putting into it my professional expertise, my curriculum and my hobbies!
So stay tuned, I hope to see you back again in a few days!