Ócáid
Mar 31, 11 PM - Apr 2, 11 PM
An ócáid foghlama SQL, Fabric and Power BI is mó. Márta 31 – 2 Aibreán. Bain úsáid as cód FABINSIDER chun $ 400 a shábháil.
Cláraigh inniuNí thacaítear leis an mbrabhsálaí seo a thuilleadh.
Uasghrádú go Microsoft Edge chun leas a bhaint as na gnéithe is déanaí, nuashonruithe slándála, agus tacaíocht theicniúil.
Have you ever gone through the SQL Server installation interface just by selecting the same buttons, entering the same information, and not giving it a second thought? The installation finished, but you forgot to specify the DBA group in the sysadmin role. Then you had to do these things:
What's worse is now the confidence of the entire installation is shaken. "What else did I forget?" you might ask yourself.
Read about PowerShell Desired State Configuration (DSC). By using DSC, you build one configuration template that you can reuse over hundreds and thousands of servers. Depending on the build, you might have to tweak a few of the setup parameters. But that's not a significant issue because you can keep all of the standard settings in place. It eliminates the possibility that you'll forget to enter an important parameter.
This article explores the initial setup of a standalone instance of SQL Server 2017 on Windows Server 2016 by using the SqlServerDsc DSC resource. Some prior knowledge of DSC is helpful as we won't explore how DSC works.
Nóta
This article refers to PowerShell 5.1, which is the default version of PowerShell installed with Windows Server 2016, 2019, and 2022.
The following items are required for this walkthrough:
In most cases, DSC is used to handle the prerequisite requirements. But for the purposes of this demo, we handle the prerequisites manually.
Download the SqlServerDsc DSC resource from the PowerShell Gallery by using the Install-Module cmdlet.
Nóta
Make sure PowerShell is running As Administrator to install the module.
Install-Module -Name SqlServerDsc
Download the SQL Server 2017 installation media to the server. We downloaded SQL Server 2017 Enterprise from a Visual Studio subscription and copied the ISO to C:\en_sql_server_2017_enterprise_x64_dvd_11293666.iso
.
Now the ISO must be extracted to a directory:
New-Item -Path C:\SQL2017 -ItemType Directory
$mountResult = Mount-DiskImage -ImagePath 'C:\en_sql_server_2017_enterprise_x64_dvd_11293666.iso' -PassThru
$volumeInfo = $mountResult | Get-Volume
$driveInfo = Get-PSDrive -Name $volumeInfo.DriveLetter
Copy-Item -Path ( Join-Path -Path $driveInfo.Root -ChildPath '*' ) -Destination C:\SQL2017\ -Recurse
Dismount-DiskImage -ImagePath 'C:\en_sql_server_2017_enterprise_x64_dvd_11293666.iso'
Create the configuration function that will be called to generate the Managed Object Format (MOF) documents:
Configuration SQLInstall
{...}
Import the modules into the current session. These modules tell the configuration document how to build the MOF documents. They also tell the DSC engine how to apply the MOF documents to the server:
Import-DscResource -ModuleName SqlServerDsc
SQL Server relies on the .NET Framework. So we need to make sure it's installed before we install SQL Server. The WindowsFeature resource is used to install the Net-Framework-45-Core Windows feature:
WindowsFeature 'NetFramework45'
{
Name = 'Net-Framework-45-Core'
Ensure = 'Present'
}
The SqlSetup resource is used to tell DSC how to install SQL Server. The parameters required for a basic installation are as follows:
C:\SQL2017
. A network share can minimize the space used on the server.Nóta
We don't recommend this configuration in a high-security environment.
A full list and description of the parameters available on SqlSetup are available on the SqlServerDsc GitHub repository.
The SqlSetup resource installs only SQL Server and doesn't maintain the settings that are applied. An example is if the SQLSysAdminAccounts are specified at installation time. An admin might add or remove sign-ins to or from the sysadmin role. But the SqlSetup resource won't be affected. If you want DSC to enforce the membership of the sysadmin role, use the SqlServerRole resource.
Configuration SQLInstall
{
Import-DscResource -ModuleName SqlServerDsc
node localhost
{
WindowsFeature 'NetFramework45'
{
Name = 'NET-Framework-45-Core'
Ensure = 'Present'
}
SqlSetup 'InstallDefaultInstance'
{
InstanceName = 'MSSQLSERVER'
Features = 'SQLENGINE'
SourcePath = 'C:\SQL2017'
SQLSysAdminAccounts = @('Administrators')
DependsOn = '[WindowsFeature]NetFramework45'
}
}
}
Dot source the configuration script:
. .\SQLInstallConfiguration.ps1
Run the configuration function:
SQLInstall
A directory called SQLInstall is created in the working directory. It contains a file called localhost.mof. Examine the contents of the MOF, which shows the compiled DSC configuration.
To start the DSC deployment of SQL Server, call the Start-DscConfiguration cmdlet. The following parameters are provided to the cmdlet:
C:\SQLInstall
.Start-DscConfiguration -Path C:\SQLInstall -Wait -Force -Verbose
As the configuration applies, the verbose output shows you what's happening. As long as no errors (red text) are thrown, when Operation 'Invoke CimMethod' complete appears on the screen, SQL Server should be installed.
The Test-DscConfiguration cmdlets can determine if the current state of the server meets the desired state. In this case, it's the SQL Server installation. The result of Test-DscConfiguration should be True:
PS C:\> Test-DscConfiguration
True
The services list now returns SQL Server services:
PS C:\> Get-Service -Name *SQL*
Status Name DisplayName
------ ---- -----------
Running MSSQLSERVER SQL Server (MSSQLSERVER)
Stopped SQLBrowser SQL Server Browser
Running SQLSERVERAGENT SQL Server Agent (MSSQLSERVER)
Running SQLTELEMETRY SQL Server CEIP service (MSSQLSERVER)
Running SQLWriter SQL Server VSS Writer
PS C:\> & sqlcmd -S $env:COMPUTERNAME
1> SELECT @@SERVERNAME
2> GO
1> quit
Windows PowerShell Desired State Configuration Overview
Ócáid
Mar 31, 11 PM - Apr 2, 11 PM
An ócáid foghlama SQL, Fabric and Power BI is mó. Márta 31 – 2 Aibreán. Bain úsáid as cód FABINSIDER chun $ 400 a shábháil.
Cláraigh inniuOiliúint
Modúl
Perform post-installation configuration of Windows Server - Training
Perform post-installation configuration of Windows Server
Deimhniú
Microsoft Certified: Azure Database Administrator Associate - Certifications
Administer an SQL Server database infrastructure for cloud, on-premises and hybrid relational databases using the Microsoft PaaS relational database offerings.
Doiciméadúchán
Install SQL Server Using SysPrep - SQL Server
This article describes how to prepare and complete images by using SysPrep in SQL Server installation.
Install SQL Server using a configuration file - SQL Server
You can use SQL Server Setup to generate a configuration file to deploy SQL Server across your organization using a uniform configuration.
Install and configure SQL Server on Windows from the command prompt - SQL Server
This article describes command prompt parameters for SQL Server installation on Windows. You can specify features to install and configure.
Configure Server Core Installation - SQL Server
This article covers details about configuring SQL Server on a Server Core installation, including troubleshooting tools.