Purclot
Purclot

Reputation: 559

PowerShell runtime execption in remote call

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.

Upvotes: 1

Views: 268

Answers (1)

Purclot
Purclot

Reputation: 559

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.

Upvotes: 1

Related Questions