I am trying to create a shell script to run a query and store the output, and I've got my script looking like this so far:
push-location;
import-module SqlPs;
Pop-Location;
$myData = invoke-sqlcmd -InputFile "C:\<path>\blah.sql" -serverinstance dbatest -database testdb;
$mydata | out-file C:\Users\<path>\shelloutput.csv;
remove-module sqlps;
It loads SqlPs fine which I can check with with Get-Module -ListAvailable producing this
but when I do invoke-sqlcmd it is not recognized:
Any ideas as to what else I can do?
Edit 1
When I add the option -Verbose I see this error
saying that some files are already present. Is this error preventing me from loading the module? When I do Get-Module it doesn't list the SQLPS module.
EDIT 2
Loading the 32 bit version gives me fewer errors but still errors loading files...now only 2 files are missing as opposed to 5 earlier
Get-Module -ListAvailableshows what modules are present, not which ones were loaded. Drop the-ListAvailableto show what is loaded into the current session. - Mike Shepardimport-module sqlps -forcebut that didn't help - ModeratC:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exeand see if that can loadSQLPS. - briantist