簡體   English   中英

遠程調用中的 PowerShell 運行時執行

[英]PowerShell runtime execption in remote call

我打算遠程安裝一個 sql 實例。 我與 sql-binaries 和一個配置文件共享。 我的腳本是:

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

我仍然收到錯誤,不知道如何解釋它:

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

我在服務器 A:(C:\temp\script.ps1) 上有一個 PS 腳本,內容如下:

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

我想在服務器 B 上執行這個腳本(安裝一個 sql 服務器)。 這不起作用:

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

再次更新:完整的調用如下所示:

# 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
}

更新:2 我創建了一個包含以下內容的文件(test5.ps1):

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

然后我像這樣調用這個腳本:

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

然后腳本開始在遠程機器上安裝 sql 服務器,但我仍然收到錯誤(在遠程機器上安裝 sql 服務器的 summary.txt 中):訪問被拒絕。 錯誤結果:-2061762559 結果設施代碼:1308 結果錯誤代碼:1

含義:憑據仍然存在問題。

更新 3:

  1. 腳本 (test5.ps1) 保持不變
  2. 在調用方站點上:$cred = get-credential Invoke-Command -ComputerName xxx-sql-yyy -FilePath C:\Users\xxx\Documents\test\test5.ps1 -Credential $cred

不幸的是,同樣的錯誤:訪問被拒絕等。

棘手的問題是在無人值守 sql 服務器安裝的 configuration.ini 文件中,即:

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

錯誤消息“拒絕訪問”都是關於這些帳戶的。 安裝后,我必須更改 sql 和代理服務的服務帳戶,僅此而已。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM