This is a PowerShell script that puts out the XML required to update your Red Gate MultiScript servers. Manually entering the SQL instances from within the application can be a daunting task if you have a large number to do. This script will have you up and running in seconds....
Powershell
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; }
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: Here is the PowerShell script: $server_name = "name_of_server"; $services...
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...
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. cls cd \\DIRECTORY_NAME\CHANGE_THIS...
Getting all SQL Server services running on a server using PowerShell: Get-WmiObject -Class sqlservice -Namespace “ROOT\Microsoft\SqlServer\ComputerManagement11” | Select ServiceName Additionally, this can be set to an array and worked with as such. $services = Get-WmiObject -Class sqlservice -Namespace “ROOT\Microsoft\SqlServer\ComputerManagement11” | Select ServiceName foreach($service in $services) { $service.ServiceName } $services[0].ServiceName >>...
The basics of creating a PowerShell array and working with it.
PowerShell script that prints out the state of the node you are on – Active or Passive.
The basic syntax for sending a query to SQL Server using PowerShell. sqlcmd -S SERVER_NAME -d master -Q "select count(1) from sys.objects"