Many database related tasks can be automated using PowerShell. This T-SQL script can be used to check the following:

  1. Is PowerShell installed on your local SQL Server?
  2. Is it enabled for script execution?
  3. What is the version of PowerShell installed on your machine?

You can obtain all the above information using the below T-SQL script. Since we have to obtain information from the server registry and from the output of PowerShell.exe file, we will be using both sys,xp_regread and xp_cmdshell extended stored procedures in this example:

Note: That the user running the above script must have sysadmin permissions to use both sys,xp_regread and xp_cmdshell.