我正在尝试在远程 Powershell session 上使用以下命令,通过 Chocolatey 将 SQL Server 2017 在无人值守的情况下安装到 Windows 10 Azure 虚拟机中:
choco install sql-server-express -ia ""/IACCEPTSQLSERVERLICENSETERMS /FEATURES=SQLEngine /Q /ACTION=install /INSTANCEID=[INSTANCE_NAME] /INSTANCENAME=SQLCHEMETER /FILESTREAMLEVEL=1 /SECURITYMODE=SQL /SAPWD=[SA_PASSWORD] /UPDATEENABLED=FALSE"" -o -y"
但是安装失败,日志文件只告诉我抛出了这个异常:
(01) 2018-08-14 06:42:11 Slp: Inner exceptions are being indented
(01) 2018-08-14 06:42:11 Slp:
(01) 2018-08-14 06:42:11 Slp: Exception type: Microsoft.SqlServer.Chainer.Infrastructure.ChainerInfrastructureException
(01) 2018-08-14 06:42:11 Slp: Message:
(01) 2018-08-14 06:42:11 Slp: There was an error generating the XML document.
(01) 2018-08-14 06:42:11 Slp: HResult : 0x84b10001
(01) 2018-08-14 06:42:11 Slp: FacilityCode : 1201 (4b1)
(01) 2018-08-14 06:42:11 Slp: ErrorCode : 1 (0001)
(01) 2018-08-14 06:42:11 Slp: Stack:
(01) 2018-08-14 06:42:11 Slp: at Microsoft.SqlServer.Chainer.Infrastructure.DataStoreService.SerializeObject(String rootPath, Object objectToSerialize, Boolean saveToCache)
(01) 2018-08-14 06:42:11 Slp: at Microsoft.SqlServer.Chainer.Infrastructure.DataStoreService.SerializeObject(Object objectToSerialize)
(01) 2018-08-14 06:42:11 Slp: at Microsoft.SqlServer.Chainer.Infrastructure.PublicConfigurationBridge.Calculate()
(01) 2018-08-14 06:42:11 Slp: at Microsoft.SqlServer.Chainer.Infrastructure.InputSettingService.CalculateSettings(IEnumerable`1 settingIds)
(01) 2018-08-14 06:42:11 Slp: at Microsoft.SqlServer.Chainer.Infrastructure.InputSettingService.CalculateAllSettings(Boolean chainerSettingOnly)
(01) 2018-08-14 06:42:11 Slp: at Microsoft.SqlServer.Chainer.Infrastructure.Action.Execute(String actionId, TextWriter errorStream)
(01) 2018-08-14 06:42:11 Slp: at Microsoft.SqlServer.Setup.Chainer.Workflow.ActionInvocation.<>c__DisplayClasse.<ExecuteActionWithRetryHelper>b__b()
(01) 2018-08-14 06:42:11 Slp: at Microsoft.SqlServer.Setup.Chainer.Workflow.ActionInvocation.ExecuteActionHelper(ActionWorker workerDelegate)
(01) 2018-08-14 06:42:11 Slp: Inner exception type: System.InvalidOperationException
(01) 2018-08-14 06:42:11 Slp: Message:
(01) 2018-08-14 06:42:11 Slp: There was an error generating the XML document.
(01) 2018-08-14 06:42:11 Slp: HResult : 0x80131509
(01) 2018-08-14 06:42:11 Slp: Stack:
(01) 2018-08-14 06:42:11 Slp: at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
(01) 2018-08-14 06:42:11 Slp: at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)
(01) 2018-08-14 06:42:11 Slp: at Microsoft.SqlServer.Chainer.Infrastructure.DataStoreService.SerializeObject(String rootPath, Object objectToSerialize, Boolean saveToCache)
(01) 2018-08-14 06:42:11 Slp: Inner exception type: System.Security.Cryptography.CryptographicException
(01) 2018-08-14 06:42:11 Slp: Message:
(01) 2018-08-14 06:42:11 Slp: Access is denied.
(01) 2018-08-14 06:42:11 Slp:
(01) 2018-08-14 06:42:11 Slp: HResult : 0x80070005
(01) 2018-08-14 06:42:11 Slp: Stack:
(01) 2018-08-14 06:42:11 Slp: at System.Security.Cryptography.ProtectedData.Protect(Byte[] userData, Byte[] optionalEntropy, DataProtectionScope scope)
(01) 2018-08-14 06:42:11 Slp: at Microsoft.SqlServer.Common.SqlSecureString.WriteXml(XmlWriter writer)
(01) 2018-08-14 06:42:11 Slp: at System.Xml.Serialization.XmlSerializationWriter.WriteSerializable(IXmlSerializable serializable, String name, String ns, Boolean isNullable, Boolean wrapped)
(01) 2018-08-14 06:42:11 Slp: at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterAgentConfigurationPublic.Write6_AgentConfigurationPublic(String n, String ns, AgentConfigurationPublic o, Boolean isNullable, Boolean needType)
(01) 2018-08-14 06:42:11 Slp: at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterAgentConfigurationPublic.Write7_AgentConfigurationPublic(Object o)
我已经检查过,启动它的用户具有管理员权限。
但是只有当我之前没有通过远程桌面连接到计算机时才会发生这种情况,如果我连接然后启动该过程,它会顺利进行。
问题是这必须是一个自动化过程,因此我无法打开与创建的计算机的远程桌面连接。
有人知道发生了什么吗?
谢谢。
最佳答案
在悬赏后不久我自己就发现了这一点。 CredSSP 可以解决这个问题,但它并不像一句台词那么简单。基本上,这是“双跳”问题,如果您没有通过身份验证,就会遇到此错误。
要启用 CredSSP,您需要在服务器上运行它(您尝试安装 SQL Server 的远程主机:
Enable-WSManCredSSP -Role Server -Force
您还需要在客户端(委托(delegate)给服务器的计算机)上启用 CredSSP:
Enable-WSManCredSSP -Role client -DelegateComputer $nameOrIp -Force
此外,您需要在客户端上允许凭据委派,这可以使用以下脚本在 PowerShell 中自动完成:
$allowed = @("WSMAN/$nameOrIp")
$key = 'hklm:\SOFTWARE\Policies\Microsoft\Windows\CredentialsDelegation'
if (!(Test-Path $key)) {
md $key
}
New-ItemProperty -Path $key -Name AllowFreshCredentials -Value 1 -PropertyType Dword -Force
$key = Join-Path $key 'AllowFreshCredentials'
if (!(Test-Path $key)) {
md $key
}
$i = 1
$allowed |% {
New-ItemProperty -Path $key -Name $i -Value $_ -PropertyType String -Force
$i++
}
如果您还没有这样做,请确保两台计算机已将对方设置为受信任的主机:
$curList = (Get-Item WSMan:\localhost\Client\TrustedHosts).value
$exists = $curList -match $nameOrIp
if ($exists -eq $false) {
"Adding IP to trusted hosts..."
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "$curList, $nameOrIp" -Force
}
最后,使用现有 session 对我来说不起作用,我不得不使用 -Authentication CredSSP
发送 Invoke-Command
:
$cred = New-Object System.Management.Automation.PSCredential ($adminName, $secureWindowsPassword)
Invoke-Command -Computername $nameOrIp -Authentication CredSSP -Credential $cred -ScriptBlock {
Param($sqlPass)
Start-Process -FilePath C:\temp\SQLEXPR_x64_ENU.exe -Args "/ConfigurationFile=C:\temp\MSSQL.ini /SAPWD='$sqlPass' /Q /HIDECONSOLE /UpdateEnabled=FALSE" -Verb RunAs -Wait 4>&1
} -ArgumentList $sqlPass
关于sql-server - 尝试无人值守安装 SQL Server 2017 时出现错误 "There was an error generating the XML document",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51840565/