Quote from Import SQLPS Module on MSDN,
The recommended way to manage SQL Server from PowerShell is to import the sqlps module into Windows PowerShell 2.0.
So, yes, you could use the Add-PSSnapin approach described in detail by Christian, but it is also useful to evaluate the recommended approach of the sqlps module.
The simplest case assumes that you have SQL Server 2012: sqlps is included in the installation, so you just download the module, like any other (usually in profile ) through Import-Module sqlps . You can check if a module is available on your system using Get-Module -ListAvailable .
If you do not have SQL Server 2012, you just need to load the sqlps module into the modules directory so that Get-Module / Import-Module will find it. Curiously, Microsoft does not make this module available for download! However, Chad Miller kindly packed the necessary items and provided this download module . Unzip it to your ... Documents \ WindowsPowerShell \ Module Directory and continue importing.
It is interesting to note that the modular approach and the snapin approach are not identical. If you download snapins, run Get-PSSnapin (without the -Registered parameter to show only what you downloaded) you will see snapins SQL. If, on the other hand, you download the sqlps Get-PSSnapin , it will not show the loaded snapins, so various blog entries that check the Invoke-Sqlcmd cmdlet only by checking the snapins can produce a false negative result.
2012.10.06 Update
For complete information on the sqlps module and the sqlps mini-shell vs. snap-in SQL Server check out my two-part mini-series Practical PowerShell for SQL Database Developers and Administrators, recently published on Simple-Talk.com, where I, according to one reader comment, successfully "confused" the problem. :-)
Michael Sorens Jun 06 2018-12-06T00: 00Z
source share