Using PowerShell to Manage SQL Server

After reviewing the
Library folder  now it’s time  to load it in order
to call the functions and use these from Powershell.  The file responsible for load our entire
PowerShell DBA framework is DBAProfile.ps1; which both imports the SQLPSX modules
and calls the  custom fileslibrary of functions.  

The final step is to run DBAProfile.ps1. In the PowerShell command prompt
type “.”  and then the space bar and the full path including the DBAProfile.ps1 file.
Hit Return and now you will be able to run any custom command in addition to those
built-in from SQLPSX modules.

Note that I am using $pshome in the file path. $pshome is the environment
variable that holds the Windows PowerShell’s root path –

If you prefer to have
the DBA profile loaded by default when you start a PowerShell session, edit the
Windows PowerShell default profile profile.ps1 located under the home directory
($pshome) C:WindowsSystem32WindowsPowerShellv1.0 and add a line calling the
DBAProfile.ps1 file. 

The below screenshot demonstrates the DBA profile being loaded and all the commands listed. Now, we can access the set of commands customized to
manage SQL Server databases anywhere under the PowerShell session
without providing the file names and paths.


Leave a Reply

Your email address will not be published. Required fields are marked *