远程安装SQL Server

时间:2019-02-27 10:55:42

标签: sql-server powershell

我正在尝试使用PowerShell在远程计算机上安装SQL Server 2016。下面是我的脚本。有人可以帮助您确定问题吗?

# Variables
$INSTANCENAME = 'DB1234INST01'
$VOLNAME = '1234INST01'
$SAPASS = "abc@12345"
$InstMem = '4096'

Invoke-Command  -ComputerName DB12345 -ScriptBlock{

# Install SQL Instance
D:\Setup.exe `
/SkipRules=RebootRequiredCheck `
/ACTION=Install `
/AGTSVCSTARTUPTYPE=Automatic `
/BROWSERSVCSTARTUPTYPE=Automatic `
/ERRORREPORTING=False `
/FEATURES="SQLEngine,DQ" `
/IACCEPTSQLSERVERLICENSETERMS `
/INSTANCEDIR="E:\$VOLNAME" `
/INSTANCEID=$INSTANCENAME `
/INSTANCENAME=$INSTANCENAME `
/ISSVCSTARTUPTYPE=Automatic `
/QUIETSIMPLE `
/SAPWD=$SAPASS `
/SECURITYMODE=SQL `
/SQLSVCSTARTUPTYPE=Automatic `
/SQLSYSADMINACCOUNTS="bac\Domain Admins" "bac\DB Admins" `
/SQMREPORTING=False `
/TCPENABLED=1 `
/UpdateEnabled=1 `
/UpdateSource=MU

#Set Memory on Instance
import-module SQLPS -DisableNameChecking
Invoke-Sqlcmd -ServerInstance .\$INSTANCENAME -Username sa -Password $SAPASS -Query "EXEC sys.sp_configure 'show advanced options', 1"
Invoke-Sqlcmd -ServerInstance .\$INSTANCENAME -Username sa -Password $SAPASS -Query "RECONFIGURE"
Invoke-Sqlcmd -ServerInstance .\$INSTANCENAME -Username sa -Password $SAPASS -Query "EXEC sys.sp_configure 'max server memory (MB)', $InstMem"
Invoke-Sqlcmd -ServerInstance .\$INSTANCENAME -Username sa -Password $SAPASS -Query "EXEC sys.sp_configure 'show advanced options', 0"
Invoke-Sqlcmd -ServerInstance .\$INSTANCENAME -Username sa -Password $SAPASS -Query "RECONFIGURE"

}

从远程计算机(如跳转主机)运行时,我遇到以下错误:

SQL Server 2016 transmits information about your installation experience, as well as other usage and performance data, to Microsoft to help improve 
the product. To learn more about SQL Server 2016 data processing and privacy controls, please see the Privacy Statement.
The following error occurred:
The specified value for setting 'SAPWD' is invalid. The expected value type is SqlSecureString.

Error result: -2068578303
Result facility code: 1204
Result error code: 1

Please review the summary.txt log for further details
Microsoft (R) SQL Server 2016 13.00.1601.05

Copyright (c) 2016 Microsoft Corporation.  All rights reserved.


Could not load file or assembly 'Microsoft.SqlServer.ConnectionInfo, Version=13.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of 
its dependencies. The system cannot find the file specified.
    + CategoryInfo          : NotSpecified: (:) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand
    + PSComputerName        : DB12345

2 个答案:

答案 0 :(得分:1)

问题帖中几乎没有错误。由于缺少SMO(SQL共享管理对象)而出现其中之一:

Could not load file or assembly 'Microsoft.SqlServer.ConnectionInfo, Version=13.0.0.0

可以从SQL Server功能包page下载


如果安装没有帮助,请同时查看以下线程: Could not load file or assembly microsoft.sqlserver.sqlclrprovider 13.100.0.0

有一个相关的ms连接项的引用...

更新2019-02-09:

/QUIETSIMPLE
  

指定安装程序运行并通过UI显示进度,但是   不接受任何输入或显示任何错误消息。

/QUIET
  

指定安装程序在无任何用户界面的安静模式下运行。   这用于无人值守的安装。 / Q参数覆盖   / QS参数的输入。

将Setup.exe参数从/QUIETSIMPLE更改为/QUIET,因为通过Invoke-Command远程执行对QUIETSIMPLE带来的交互性不满意

答案 1 :(得分:0)

我已经解决了远程安装SQL的问题,并且可以正常工作。现在唯一的问题是我无法将内存值修改为创建的实例。 Invoke-Sqlcmd -ServerInstance $ Servers \ $ INSTANCENAME命令以某种方式表明其无法连接到服务器或未找到的实例。在这种情况下的任何想法都将有所帮助。

变量

$Servers = Get-Content C:\server.txt

Invoke-Command -ComputerName $Servers{

$INSTANCENAME = 'DB1243INST01'
$VOLNAME = '1243INST01'
$SAPASS = 'test123'
$InstMem = '4096'
# Install SQL Instance
C:\Temp\Setup.exe `
/SkipRules=RebootRequiredCheck `
/ACTION=Install `
/AGTSVCSTARTUPTYPE=Automatic `
/BROWSERSVCSTARTUPTYPE=Automatic `
/ERRORREPORTING=False `
/FEATURES="SQLEngine,DQ" `
/IACCEPTSQLSERVERLICENSETERMS `
/INSTANCEDIR="E:\$VOLNAME" `
/INSTANCEID=$INSTANCENAME `
/INSTANCENAME=$INSTANCENAME `
/ISSVCSTARTUPTYPE=Automatic `
/QUIET `
/SAPWD=$SAPASS `
/SECURITYMODE=SQL `
/SQLSVCSTARTUPTYPE=Automatic `
/SQLSYSADMINACCOUNTS="abc\Admins" "abc\DB Admins" `
/SQMREPORTING=False `
/TCPENABLED=1 `
/UpdateEnabled=FALSE `
/UpdateSource=MU `

#Set Memory on Instance
import-module SQLPS -DisableNameChecking
Invoke-Sqlcmd -ServerInstance $Servers\$INSTANCENAME -Username sa -Password $SAPASS -Query "EXEC sys.sp_configure 'show advanced options', 1"
Invoke-Sqlcmd -ServerInstance $Servers\$INSTANCENAMEE -Username sa -Password $SAPASS -Query "RECONFIGURE"
Invoke-Sqlcmd -ServerInstance $Servers\$INSTANCENAMEE -Username sa -Password $SAPASS -Query "EXEC sys.sp_configure 'max server memory (MB)', $InstMem"
Invoke-Sqlcmd -ServerInstance $Servers\$INSTANCENAME -Username sa -Password $SAPASS -Query "EXEC sys.sp_configure 'show advanced options', 0"
Invoke-Sqlcmd -ServerInstance $Servers\$INSTANCENAME -Username sa -Password $SAPASS -Query "RECONFIGURE"

}