Install Invoke-SQLCMD (PowerShell Extensions for SQL Server)

Possible error: Invoke-sqlcmd : The term ‘Invoke-sqlcmd’ is not recognized as the name of a cmdlet, function, script file, or operable

Solution: Install PowerShell Extensions for SQL Server from Microsoft SQL Server 2016 Feature Pack. Once you install it you will be able to run ‘Invoke-sqlcmd’ in Powershell.

Download below installation files from Microsoft® SQL Server® 2016 Feature Pack site and install them following the below order:

  1. Microsoft® System CLR Types for Microsoft SQL Server® 2016 (SQLSysClrTypes.msi)
  2. Microsoft® SQL Server® 2016 Shared Management Objects (SharedManagementObjects.msi)
  3. Microsoft® Windows PowerShell Extensions for Microsoft SQL Server® 2016 (PowerShellTools.msi)

If you have any difficult in the installation let me know in the comments.

After installation open new PS window and check it’s working accessing some SQL instance. Reboot is not required.

Invoke-sqlcmd -ServerInstance “Server\Instance” -Query “SELECT GETDATE() AS TimeOfQuery”

TimeOfQuery
———–
7/5/2018 6:51:57 PM

 

46 thoughts on “Install Invoke-SQLCMD (PowerShell Extensions for SQL Server)

Leave a Reply

Your email address will not be published. Required fields are marked *