I was recently using the following line in one of my PowerShell scripts to run SQL Server database commands:
Add-PSSnapin SqlServerCmdletSnapin100
However, I was suddenly faced with this error message:
Add-PSSnapin: No snap-ins have been registered for Windows PowerShell version 4.
Huh?? I had installed SQL Server Management Studio, so I assumed that the PowerShell tools would be installed and available.
Well, as it turns out, I needed to install the PowerShell Tools and Shared Management Objects from the SQL Server 2014 Feature Pack here: https://www.microsoft.com/en-us/download/details.aspx?id=42295
Once I did that, I could simply use Invoke-SQLCmd directly in my PowerShell scripts, or I could simply use this line instead:
Import-Module SQLPS -DisableNameChecking
That was enough to get my PowerShell scripts which invoked SQL commands to work!
Add-PSSnapin SqlServerCmdletSnapin100
However, I was suddenly faced with this error message:
Add-PSSnapin: No snap-ins have been registered for Windows PowerShell version 4.
Huh?? I had installed SQL Server Management Studio, so I assumed that the PowerShell tools would be installed and available.
Well, as it turns out, I needed to install the PowerShell Tools and Shared Management Objects from the SQL Server 2014 Feature Pack here: https://www.microsoft.com/en-us/download/details.aspx?id=42295
Once I did that, I could simply use Invoke-SQLCmd directly in my PowerShell scripts, or I could simply use this line instead:
Import-Module SQLPS -DisableNameChecking
That was enough to get my PowerShell scripts which invoked SQL commands to work!
No comments:
Post a Comment