| title | Download SQL Server PowerShell Module |
|---|---|
| description | Learn how to install the SqlServer PowerShell module, which provides cmdlets that support the latest SQL features, and also contains updated versions of the cmdlets in the SQLPS module. |
| ms.prod | sql |
| ms.technology | sql-server-powershell |
| ms.topic | conceptual |
| author | markingmyname |
| ms.author | maghan |
| ms.reviewer | matteot, drskwier |
| ms.custom | |
| ms.date | 10/14/2020 |
[!INCLUDESQL Server Azure SQL Database Synapse Analytics PDW ]
This article provides directions for installing the SqlServer PowerShell module.
There are two SQL Server PowerShell modules:
-
SqlServer: The SqlServer module includes new cmdlets to support the latest SQL features. The module also contains updated versions of the cmdlets in SQLPS. To download the SqlServer module, go to SqlServer module in the PowerShell Gallery.
-
SQLPS: The SQLPS is the module used by SQL Agent to run agent jobs in agent job steps using the PowerShell subsystem.
Note
The versions of the SqlServer module in the PowerShell Gallery support versioning and require PowerShell version 5.0 or greater.
For help topics, go to:
SQL Server Management Studio (SSMS), doesn't install either PowerShell module. To use PowerShell with SSMS, install the SqlServer module from the PowerShell Gallery.
Note
With SSMS 16.x, an earlier version of the SqlServer module is included with SQL Server Management Studio (SSMS)
Azure Data Studio doesn't install either PowerShell module. To use PowerShell with Azure Data Studio, install the SqlServer module from the PowerShell Gallery.
You can use the PowerShell extension, which provides rich PowerShell editor support in Azure Data Studio.
To install the SqlServer module from the PowerShell Gallery, start a PowerShell session as an administrator. You can also start Azure Data Studio as an administrator and run these commands in a PowerShell session in the integrated terminal.
You can also use Install-Module SQLServer -Scope CurrentUser to run elevated permissions. This cmdlet is useful for users who aren't administrators in their environment. However, since the scope is limited to the current user, other users on the same machine can't use the module.
Run the following command in your PowerShell session to install the SqlServer module for all users:
Install-Module -Name SqlServerExecute the following command to see the versions of the SqlServer module that have been installed
Get-Module SqlServer -ListAvailableIf you aren't able to run the PowerShell session as an administrator, install for the current user using the following command:
Install-Module -Name SqlServer -Scope CurrentUserYou can also use the Install-Module command to overwrite a previous version.
Install-Module -Name SqlServer -AllowClobberNote
PowerShell always uses the latest module installed.
When updated versions of the SqlServer module are available, you can install the newer version using the following command:
Install-Module -Name SqlServer -AllowClobberYou can use the Update-Module command to install the newest version of the SQLServer PowerShell module, but that doesn't remove older versions. It installs the newer version side by side to allow you the ability to experiment with the latest version, yet still have older modules installed.
However, if you don’t want to keep older module versions, then you can use the Uninstall-Module command to remove previous versions.
You can use the following command to list if more than one version is installed:
Get-Module SqlServer -ListAvailableYou can use the following command to remove older versions:
Uninstall-module -Name SQLServer -RequiredVersion "<version number>" -AllowClobberIf you run into problems installing, see the Install-Module documentation and Install-Module reference.
To use a specific version of the module, import it with a specific version number similar to the following command:
Import-Module SqlServer -Version 21.1.18218Pre-release (or "preview") versions of the SqlServer module may be available in the PowerShell Gallery.
Important
These versions may be discovered and installed by using the updated Find-Module and Install-Module cmdlets that are part of the PowerShellGet module by passing the -AllowPrerelease switch. To use these cmdlets, install the PowerShellGet module and then open a new session.
To discover the pre-release (preview) versions of the SqlServer module, run the following command:
Find-Module SqlServer -AllowPrereleaseTo install a specific pre-release version of the module, install it with a specific version number.
You can try to use the following command:
Install-Module SqlServer -RequiredVersion 21.1.18218-preview -AllowPrereleaseVisit Manage SQL Server on Linux with PowerShell Core to see how to install SQL Server PowerShell on Linux.
-
Az.Sql - SQL service cmdlets for Azure Resource Manager in Windows PowerShell and PowerShell Core.
-
SqlServerDsc - Module with DSC resources for deployment and configuration of Microsoft SQL Server.