| title | Download SQL Server PowerShell Module |
|---|---|
| ms.prod | sql |
| ms.technology | scripting |
| ms.topic | conceptual |
| author | markingmyname |
| ms.author | maghan |
| ms.reviewer | carlrab |
| ms.custom | |
| ms.date | 01/23/2020 |
[!INCLUDEappliesto-ss-asdb-asdw-pdw-md]
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 module is included with the SQL Server installation (for backward compatibility), but is no longer being updated. The most up-to-date PowerShell module is the SqlServer module.
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), beginning with version 17.0, doesn't install either PowerShell module. To use PowerShell with SSMS, install the SqlServer module from the PowerShell Gallery.
Note
With version 16.x of SSMS, 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 also start Azure Data Studio as an administrator and run these commands in a PowerShell session in the integrated terminal.
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.18080Pre-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.18040-preview -AllowPrereleaseVisit Manage SQL Server on Linux with PowerShell Core to see how to install SQL Server PowerShell on Linux.