我正在尝试通过巧克力将SQL Server 2017无人参与地安装到Windows 10 Azure虚拟机中,在远程powershell会话上使用以下命令:
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)我已经检查过了,启动它的用户拥有管理员权限。
但这只会在我之前没有连接到具有远程桌面的计算机时发生,如果我连接然后启动该进程,它将顺利进行。
问题是,这必须是一个自动化的过程,所以我不能打开与创建的机器的远程桌面连接。
有人知道这是怎么回事吗?
谢谢。
发布于 2020-08-11 08:20:33
在悬赏后不久我就想通了。CredSSP做到了这一点,但它不像一行程序那么简单。基本上,这是“双跳”问题,如果你没有通过身份验证,你就会遇到这个错误。
要启用CredSSP,您需要在服务器(尝试在其上安装SQL server的远程主机:
Enable-WSManCredSSP -Role Server -Force您还需要在客户机上启用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
}最后,使用现有的会话对我不起作用,我必须使用-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发布于 2020-03-17 15:49:29
在启动SQL Server安装程序之前,在powershell会话中运行以下命令:
Enable-WSManCredSSP -Role "Server"https://stackoverflow.com/questions/51840565
复制相似问题