To run the Invoke-sqlcmd command, use this command to meet the following requirements:
1. Install SQL Server R2 Management Objectsi in the running server
2. Execute the following statement before running the command invoke-sqlcmd.
1 add-pssnapin SqlServerCmdletSnapin1002 add-pssnapin SqlServerProviderSnapin100
View Code
Refer to the original content:
Since all of the steps I required weren ' t listed on one place, I thought I ' d list them here in case it helps anyone:
- install sql Server R2 Management Objects Using web pi (I ' m not sure on versions prior to R2 ... if you had more info, please let us know in the C omments)
- install ' Windows PowerShell Extensions for SQL Server ' from The microsoft? SQL Server? R2 Feature Pack page (it's about halfway down the page). Make sure your pick the correct flavor for your instance (+ or-bit).
- run These, commands before calling Invoke-sqlcmd In your script:
Add-pssnapin SqlServerCmdletSnapin100
Add-pssnapin SqlServerProviderSnapin100
Reference article:
PowerShell prerequisites for running the invoke-sqlcmd command