AWS Windows实例PowerShell安装SQL Server及凭证错误排查
问题:已加入域的AWS Windows实例执行SQL Server无人值守安装时,Start-Process报「用户名或密码不正确」
问题详情
在已加入域的AWS Windows实例上,通过PowerShell调用Start-Process传入域凭证启动SQL Server的setup.exe进行无人值守安装,反复出现「用户名或密码不正确」的错误。实例已确认加入域,安装程序路径也正确,多次尝试域凭证仍无法解决。
原安装代码
Write-Host "`nStarting the install of SQL Server" -ForegroundColor Green [string]$userName = 'domain\\username' [string]$userPassword = 'xyz' [securestring]$secStringPassword = ConvertTo-SecureString $userPassword -AsPlainText -Force [pscredential]$credObject = New-Object System.Management.Automation.PSCredential ($userName, $secStringPassword) Start-Process -Filepath "$driveLetter\\setup.exe" -ArgumentList "/ConfigurationFile=`\\"$temp_file_location`\\\"" -Credential $credObject -NoNewWindow -Wait -RedirectStandardOutput $standardOutputFile -RedirectStandardError $errorOutputFile
报错信息
ERROR: PS C:\Windows\system32> C:\Users\manish\Desktop\custommain.ps1 domain\neu-west-1 fetching the password from parameter stores Cleaning the outputfile error finding and replacing the domains and secrets writting the content of ini into temp file C:\xyz-softwares\ms-sql-server\scripts\batch-files\temp_ConfigurationFile.ini Mounting SQL Server Image Getting Disk drive of the mounted image Starting the install of SQL Server Start-Process : This command cannot be run due to the error: The user name or password is incorrect. At C:\xyz-softwares\ms-sql-server\scripts\powershell\ms-sqlserver-installation.ps1:65 char:2 + Start-Process -Filepath "$driveLetter\\setup.exe" -ArgumentList "/ ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand SQL Installation Failed Installation with exit code SQL Installation Failed Installation with exit code At C:\xyz-softwares\ms-sql-server\scripts\powershell\ms-sqlserver-installation.ps1:72 char:9 + throw $error_message + ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (SQL Installatio... with exit code:String) [], RuntimeException + FullyQualifiedErrorId : SQL Installation Failed Installation with exit code PS C:\Windows\system32>
排查与解决步骤
1. 验证域凭证有效性与格式
- 直接用该域账号登录实例系统,确认密码未过期、账号未锁定,能正常登录
- 尝试两种用户名格式:NTLM格式(
domain\username)和UPN格式(username@domain.com),部分场景下UPN格式的凭证验证兼容性更好
2. 调整PowerShell执行权限与参数
- 右键以管理员身份启动PowerShell再执行脚本,避免权限不足导致凭证验证失败
- 移除
-NoNewWindow参数,替换为-WindowStyle Hidden:部分场景下-NoNewWindow会干扰跨会话的凭证传递,引发验证失败
3. 检查路径转义与文件存在性
- 简化配置文件路径的转义:将原代码中
/ConfigurationFile=\"$temp_file_location\\\"改为/ConfigurationFile=\"$temp_file_location\",避免过多转义导致路径解析错误 - 手动检查
$driveLetter\setup.exe和$temp_file_location指向的文件是否存在,路径是否正确
4. 确认实例与域的连接状态
- 执行命令
nltest /dsgetdc:yourdomain.com(替换为实际域名),确认能正常获取域控制器,验证实例与域的连接正常 - 检查实例DNS设置,确保DNS服务器指向域控制器,避免DNS解析问题导致域凭证验证失败
5. 改用SQL配置文件内置凭证(推荐)
无需通过Start-Process传递凭证,直接在SQL Server的配置文件(temp_ConfigurationFile.ini)中指定服务账号:
SQLSVCACCOUNT="domain\username" SQLSVCPASSWORD="xyz" # 按需添加其他服务的账号,比如AGTSVCACCOUNT、RSSVCACCOUNT等
启动setup.exe时去掉-Credential $credObject参数,直接以实例本地系统或有权限的账号执行安装命令,让SQL安装程序自行处理凭证验证。
内容的提问来源于stack exchange,提问作者Manish Mangyani
相关产品推荐
相关产品推荐

