sql server - Cannot run Invoke-Sqlcmd in a PS1 file but can on the console -
i'm on machine sql server 2008 , according question (how execute .sql file using powershell?), i've installed powershell snapins interact sql server.
the problem have installed, can run invoke-sqlcmd command line this.
invoke-sqlcmd -inputfile "mytestfile.sql" -serverinstance '.\sql2008';
but if put line inside ps1 file run , try run so
powershell ./runsqlscript.ps1
i error
the term 'invoke-sqlcmd' not recognized name of cmdlet, function, script file, or operable program. check spelling of name, or if path included, verify path correct , try again. @ d:\temp\powershelltests\runsqlscript.ps1:1 char:14 + invoke-sqlcmd <<<< -inputfile "mytestfile.sql" -serverinstance '.\sql2008'; + categoryinfo : objectnotfound: (invoke-sqlcmd:string) [], commandnotfoundexception + fullyqualifiederrorid : commandnotfoundexception
in ps1 need add-pssnapin
, load sql snapins.
each powershell window new environment in modules , snapins not yet loaded.
Comments
Post a Comment