Installing SQL Server 2012 remotely via Powershell using Invoke-Command

I am trying to perform a SQL Server 2012 command line installation using Powershell Invoke-Command on Windows 2012 Datacenter.

The code I am using is as follows:

 $ret = Invoke-Command -ComputerName $COMPUTER -ArgumentList $MEDIA,$ACTION,$FEATURES,$INSTALLDIR,$INSTANCEID,$INSTANCENAME,$SQLDATADRIVE,$SQLLOGDRIVE,$DOMAIN,$SQLSERVERSERVICEUSER,$SQLSERVICEPASSWORD,$PRODUCTKEY,$SQLSERVERSA,$username,$ADMINPASSWD -Credential $cred -ScriptBlock {
  param($MEDIA,
     $ACTION,
     $FEATURES,
     $INSTALLDIR,
     $INSTANCEID,
     $INSTANCENAME,
     $SQLDATADRIVE,
     $SQLLOGDRIVE,
     $DOMAIN,
     $SQLSERVERSERVICEUSER,
     $SQLSERVICEPASSWORD,
     $PRODUCTKEY,
     $SQLSERVERSA,
     $USERNAME,
     $PASSWD)
  Set-Location $MEDIA
  Import-Module ServerManager
  
  if (-not [IO.Directory]::Exists($MEDIA)){
   $hn = hostname
   return 0,"Failed to find SQL Server Installer at $MEDIA on $hn"
  }
  
  $tran = ""
  Try{
   & $MEDIA\setup.exe /ACTION=$ACTION /Q /FEATURES=$FEATURES /IACCEPTSQLSERVERLICENSETERMS /UPDATEENABLED=False /INSTALLSHAREDDIR="$INSTALLDIR\Program Files\Microsoft SQL Server" /INSTALLSHAREDWOWDIR="$INSTALLDIR\Program Files (x86)\Microsoft SQL Server" /RSINSTALLMODE="FilesOnlyMode" /INSTANCEID="$INSTANCEID" /INSTANCENAME="$INSTANCENAME" /INSTANCEDIR="$INSTALLDIR\Program Files\Microsoft SQL Server" /ENU="True" /AGTSVCSTARTUPTYPE="Automatic" /SQLSVCSTARTUPTYPE="Automatic" /NPENABLED=1 /TCPENABLED=1 /RSSVCStartupType="Automatic" /ERRORREPORTING=0 /SQMREPORTING=0 /INDICATEPROGRESS /INSTALLSQLDATADIR="$SQLDATADRIVE\DATA" /SQLUSERDBDIR="$SQLDATADRIVE\DATA" /SQLUSERDBLOGDIR="$SQLLOGDRIVE\LOG" /ASDATADIR="$SQLDATADRIVE\OLAP\DATA" /ASLOGDIR="$SQLLOGDRIVE\OLAP\Log" \ASBACKUPDIR="$SQLDATADRIVE\OLAP\Backup" \ASTEMPDIR="$SQLDATADRIVE\OLAP\Temp" /ASCONFIGDIR="$SQLDATADRIVE\OLAP\Config" /ASCOLLATION="Latin1_General_CI_AS" /SQLCOLLATION="SQL_Latin1_General_CP1_CS_AS" /SQLSVCACCOUNT="$DOMAIN\$SQLSERVERSERVICEUSER" /SQLSVCPASSWORD="$SQLSERVICEPASSWORD" /AGTSVCACCOUNT="$DOMAIN\$SQLSERVERSERVICEUSER" /AGTSVCPASSWORD="$SQLSERVICEPASSWORD" /ASSVCACCOUNT="$DOMAIN\$SQLSERVERSERVICEUSER" /ASSVCPASSWORD="$SQLSERVICEPASSWORD" /RSSVCACCOUNT="$DOMAIN\$SQLSERVERSERVICEUSER" /RSSVCPASSWORD="$SQLSERVICEPASSWORD" /FTSVCACCOUNT="NT AUTHORITY\LOCAL SERVICE" /INDICATEPROGRESS > $out
  } Catch [System.Exception] {
   return 0,$_.Exception.ToString()
  }
  
  if ($tran -ne ""){
   $out += $tran
  }
  
  return 1,$out
 }

The media resides on the server that I am remoting to in powershell and the server is on the same domain. The credentials I pass are for a Domain Admin, but SQL Server fails to validate the credentials for the passed parameter for the sql service user with a Access Denied.

If I run the same command with the same user directly on the server it works fine.

My guess is that the elavated privs for Administrator are not being set when using Invoke-Command? Is there a way to utilize powershell to install SQL Server 2012 with command line option using the invoke-command and passing credentials? Or is this a limitation to the SQL Server installer. If there is can a example be provided?

July 25th, 2013 11:16am

You can use the MSSQLServer installation media locally to install a remote instance of MSSQLServer.  I believe this has been available since at least SQS2005.  It should be one of the options under install/change/update although I haven't looked at this on 2012.

Free Windows Admin Tool Kit Click here and download it now
July 25th, 2013 12:54pm

Ok, so with the help of some friends, we found a fix that works!

Prior to running the Invoke-Command I now run:

# enable CredSSP on a client computer; this command allows the client credentials to be delegated to the server01 computer.:

Enable-WsManCredSSP -Role Client -DelefateComputer server.some.domain.com

Then I add the -Authentication option to my Invoke-Command with option Credssp.

The install the works fine. Hope this helpes all.

July 25th, 2013 2:48pm

In a domain you do not need to use CredSSP unless the media is not on the same server.  The SQS installer knows how to avoid this.
Free Windows Admin Tool Kit Click here and download it now
July 25th, 2013 4:03pm

Ok, so with the help of some friends, we found a fix that works!

Prior to running the Invoke-Command I now run:

# enable CredSSP on a client computer; this command allows the client credentials to be delegated to the server01 computer.:

Enable-WsManCredSSP -Role Client -DelefateComputer server.some.domain.com

Then I add the -Authentication option to my Invoke-Command with option Credssp.

The install the works fine. Hope this helpes all.

July 25th, 2013 9:42pm

Thank you for sharing your findings. 
Free Windows Admin Tool Kit Click here and download it now
February 5th, 2014 11:54am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics