SQL Server 2019 System.Data.SqlClient namespace query
possible to call a T-SQL script rather than include it in the main body of the PowerShell script

Of course.  Just read the file contents with get-content and pass that to the function:
function SqlQuery($server, $database, $query)
{
 $connection = New-Object System.Data.SqlClient.SqlConnection
 $connection.ConnectionString = &quot;Server=$server;Database=$database;Integrated Security=True;&quot;
 $connection.Open()
 $command = $connection.CreateCommand()
 $command.CommandText = $query
 $result = $command.ExecuteReader()
 $table = new-object “System.Data.DataTable”
 $table.Load($result)
 $connection.Close()
 return $table
}

$server = &quot;localhost&quot;
$database = &quot;tempdb&quot;
$sql = get-content &quot;c:\test\foo.sql&quot;

SqlQuery $Server $Database $sql

If the sql file contains multiple batches, you'll need to break it up yourself, or use use the Invoke-Sqlcmd cmdlet from the SqlServer module, which you can install with
install-module SqlServer