You are here

Monthly archive

PowerShell - Get All SQL Instances On Server

This script will return all SQL instances running on a server or list of servers.

cls
Import-Module -Name SQLPS -DisableNameChecking

$servers = "SERVER_NAME", "SERVER_NAME_2", "ETC";

foreach($server in $servers)
{
    $path = "SQLServer:\SQL\" + $server;
    $instances = Get-ChildItem -Path $path;
    $instances;
}

PowerShell - Get "Logon As" Information From Remote (or local) Server

This was made possible by the Scripting Guy.  I have boiled it down to the answer.

If you want to use PowerShell to query for the log on account that normally is displayed in the services.msc service properties window:

T-SQL - Get Currently Running Jobs With Duration

Query to get all currently running jobs with their run duration in seconds.

Source: http://www.sanssql.com/2013/08/t-sql-query-to-find-currently-running.html

Restore All Databases With Most Recent Backup

This is a bit of a scary task.  Someone tells you about 87 databases that all need to be restored from the most recent FULL backups. You can either spend the rest of your day pointing and clicking, or you can use some PowerShell power to crank out the script and get on with your day. Here is the PowerShell way.

I don't like to fire-off the actual backups from PowerShell, rather I just use it to script out the restore script.  So, this PowerShell script will output the T-SQL restore script:

(See caution below before running this!)

PowerShell - List All Directories With Users Who Can Access

Maybe this is a one-off type of thing, but if you need to see every folder within a directory and get the list of who can access that folder, it can be done using PowerShell. The output is tab-separated and can easily paste into an Excel sheet.

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
1 + 3 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer