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.
To read a script file and place the contents with CommandText
$sqlCommand.CommandText = get-content c:\scripts\SQLText.sql