1

I intend to install remotely a sql-instance. I have a share with sql-binaries and a config-file. My script is:

import-module sqlserver -DisableNameChecking
$setupDrive = "\\sqlshare\sql_source\ISO\Setup\SW_DVD9_NTRL_SQL_Svr_Ent_Core_2019Dec2019_64Bit_English_OEM_VL_X22-22120"
$fileExe =  "$setupDrive", "setup.exe" -join("\")
$configurationFile = "\\sqlshare\sql_source\ISO\ConfigurationFileMSSQLSERVER.ini"
$session = New-PSSession -ComputerName "xxxx_yyyy"
Invoke-Command -ScriptBlock{& $args[0] /CONFIGURATIONFILE=$args[1]} -Session $session 
-ArgumentList $fileExe, $configurationFile

I'm still getting an error and don't know how to interpret it:

An error occurred while creating the pipeline.
+ CategoryInfo          : NotSpecified: (:) [], RuntimeException
+ FullyQualifiedErrorId : RuntimeException
+ PSComputerName        : xxxx_yyyy

I have a PS-script on the server A:(C:\temp\script.ps1) with this content:

import-module sqlserver -DisableNameChecking
& ("\\server1-ssp1102.my.domain\sql_source\Setup\setup.exe 
/CONFIGURATIONFILE=\\server1-ssp1102.my.domain\sql_source\SQLUnattended\ConfigurationFileMSSQLSERVER.ini")

I want to execute this script on the server B (installs a sql server). This doesn't work:

invoke-command -computer ServerB -FilePath C:\C:\temp\script.ps1 -credentials (get-credential)

Update once again: The complete call looks like following:

# A sample target computer.
$computer = 'myComputer'
# Obtain the credentials for the remote session and store them in a 
variable.
$cred = Get-Credential my\user

Invoke-Command -ComputerName $computer -Credential $cred {
$setup = '\\myShare-xxxx.my.domain\sql_source\Setup\setup.exe'
$config = '\\myShare-yyy- xxx.my.domain\sql_source\SQLUnattendedInstallation\ConfigurationFileMSSQLSERVER.ini'
$cu = '\\my-domain-xxxx.my.domain\sql_source\SQLUnattendedInstallation2019\CU'
$null = New-PSDrive -Credential $using:cred -Name cu -Root $cu -PSProvider FileSystem
$null = New-PSDrive -Credential $using:cred -Name setup -Root (Split-Path -Parent $setup) -PSProvider FileSystem
$null = New-PSDrive -Credential $using:cred -Name config -Root (Split-Path -Parent $config) -PSProvider FileSystem
& $using:setup /CONFIGURATIONFILE=$using:config
}

Update:2 I've created a file (test5.ps1) with this content:

import-module sqlserver -DisableNameChecking
$setup = '\\xxx-xxx-xxx.xxx.xxx\sql_source\Setup\setup.exe'
$config = '\\xxx-xxx- xxx.xxx.xxx\sql_source\SQLUnattendedInstallation2019\ConfigurationFileMSSQLSERVER.ini'
$cu = '\\xxx-xxx-xxx.xxx.xxx\sql_source\SQLUnattendedInstallation2019\CU\SQLServer2019-KB5014353-x64.exe'
$null = New-PSDrive -Credential $using:cred -Name cu -Root (Split- 
Path $cu) -PSProvider FileSystem
$null = New-PSDrive -Credential $using:cred -Name setup -Root 
(Split-Path -Parent $setup) -PSProvider FileSystem
$null = New-PSDrive -Credential $using:cred -Name config -Root 
(Split-Path -Parent $config) -PSProvider FileSystem

& $setup /CONFIGURATIONFILE=$config

and then I'm calling this script like this:

Invoke-Command -ComputerName xxx-sql-yyy -FilePath 
C:\Users\xxx\Documents\test\test5.ps1 -Credential (Get-Credential 
my\user)

then the script begins to install the sql server on the remote machine, but still I get an error (in the summary.txt from the sql server installation on the remote machine): Access is denied. Error result: -2061762559 Result facility code: 1308 Result error code: 1

meaning: still a problem with the credentials.

Update 3:

  1. The script (test5.ps1) stays untouched
  2. on the caller-site: $cred = get-credential Invoke-Command -ComputerName xxx-sql-yyy -FilePath C:\Users\xxx\Documents\test\test5.ps1 -Credential $cred

Unfortunately the same error: Access denied etc.

19
  • 1
    Are you able to run any command on the remote machine? Say, a simple hostname call? If so, are you able to connect from the remote server to the $setupDrive share from within your remote session? You may be hitting the double-hop problem Commented Aug 18, 2022 at 13:34
  • 1
    Check out the using prefix, which is a better way to pass variables. Commented Aug 18, 2022 at 14:08
  • 1
    Your syntax is correct. Have you looked into the double-hop problem pointed out by @boxdog? This answer shows a workaround. If that works, we can close this post as a duplicate. Commented Aug 29, 2022 at 12:29
  • 1
    @Purclot, the linked answer as well as boxdog's link above have background information about the double-hop problem - I'm unsure about the specific symptoms, but in short: irrespective of what credentials you use for remoting, the remotely running script block cannot access resources on yet another machine. The suggested workaround requires you to pass credentials explicitly so you can use them to establish a (temporary) drive mapping to the share of interest on the other machine, after which accessing the share works. Commented Aug 29, 2022 at 19:13
  • 1
    @mklement0, Thanks a lot, I'll test it immediately tomorrow (my German time is 22 hours and my shift is over for today). Commented Aug 29, 2022 at 19:55

1 Answer 1

1

the tricky problem was inside of the configuration.ini file for unattended sql server installation, namely:

;SQLSVCACCOUNT="myDomain\theServiceAccount$" # originally
SQLSVCACCOUNT="NT Service\MSSQLServer" # changed
;AGTSVCACCOUNT="myDomain\theAgentAccount$" # originally
AGTSVCACCOUNT="NT Service\SQLServerAgent" # changed

The error-message "Access denied" was all about those accounts. After the installation I have to change the service accounts for the sql- and agent services and that's all.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.