Home Forums Programming Powershell Loop thru SQL files, second file doesnt run when results are aliased RE: Loop thru SQL files, second file doesnt run when results are aliased

  • This will return the first column from each query, regardless of name:

    $FolderPath = 'C:\users\lyonsg\Documents\Scripts\Powershell\HelloWorldTest\'

    #Loop through the .sql files and run them

    foreach ($filename in get-childitem -path $FolderPath -filter "*.sql" | sort-object) {

    (invoke-sqlcmd –ServerInstance $SQLServer -InputFile $filename.fullname).Item(0)

    }

    If you need more than one column might be more complicated.