18 November,2014 by Jack Vamvas
Question: How can I read the script contents into the Powershell CommandText ?
Normally I place the query text with the Powershell CommandText , but on this occasion I want to read a large query from a sql file.
$sql.CommandText = "SELECT name from sys.sysdatabases”
Answer: Reading the contents from a script file is a good idea as it allows you to reuse your script library and maintain them in a script library.
$sqlCommand.CommandText = get-content c:\scripts\SQLText.sql