We can query SQL Server from within PowerShell. This chapter illustrates different ways in which we can send and execute queries in SQL Server using PowerShell, and also evaluate when it is appropriate to use this method to do the job.
The topics that will be covered in this chapter are as follows:
To PowerShell or not to PowerShell
Sending queries to SQL Server
Fixing orphaned users
Getting fragmentation data
Backing up and restoring databases
Exporting data using
bcp