Category: PowerShell

Setting SQL Alias with PowerShell

Sal Young | September 2nd, 2014


PROBLEM: The SQL Servers instances I manage have long cryptic names that are almost impossible to memorize and too many keystrokes to type; besides, I rather use my memory for other things. How can I set up aliases for all the SQL instances I manage in a quick an easy manner? SOLUTION: The configuration of […]

Read More

Cómo Cambiar el Propietario de Una Base de Datos

Sal Young | August 28th, 2014


PROBLEMA: Tengo base de datos donde el propietario no es “sa”, cómo puedo cambiar el propietario de varias bases de datos a “sa” de una forma dinámica. SOLUCION: Yo utilizo el cmdlet Get-SqlDatabase del módulo SqlServer para capturar las bases de datos de una instancia de SQL Server. Entonces hago una búsqueda en el objeto […]

Read More

Change Database Ownership

Sal Young | August 28th, 2014


PROBLEM: Database ownership is set to the user who created or restored the database and I want to change it to “SA”. SOLUTION: I use the Get-SqlDatabase cmdlet from SqlServer module to capture the list of databases from the SQL instance. I then pipe and search for databases where the “.owner” property is not “sa”. […]

Read More

How to Find a Database User in Your SQL Environment

Sal Young | September 15th, 2011


PROBLEM: Sal Young is a member of your DBA team and today is his last day at work. You need to find out if his login is mapped to any database throughout your MS SQL environment. SOLUTION: I used Central Management Server, PowerShell, and SQLPSX. I queried my Central Management Server to get the name […]

Read More

How To Change the SQL Server Agent Job Owner

Sal Young | April 12th, 2011


PROBLEM: I need to change the owner of several SQL Server Agent Jobs. Is there an easy way to do it? SOLUTION: Use PowerShell and SQLPSX. I use the Get-AgentJob function from SQL Server PowerShell Extension (SQLPSX) to find the jobs I need to modify. I need to change ownership of all SQL Server Agent […]

Read More

How to Copy All Tables Definition with PowerShell

Sal Young | February 14th, 2011


PROBLEM: You need to copy the table definition for all tables in a database between two SQL servers. SOLUTION: One of the requirements is to use PowerShell and I will use it in combination with SQLPSX. Yes, I will use SQLPSX again and you probably have noticed I use it in all my PowerShell scripts […]

Read More

Cómo Copiar el Esquema de Tablas Utilizando PowerShell

Sal Young | February 14th, 2011


PROBLEMA: Necesitas copiar el esquema de tablas de un servidor Microsoft SQL a otro servidor SQL. SOLUCION: Para resolver este problema utilizo PowerShell y el SQLPSX. Si sigues este blog, podrás notar que utilizo la extensión SQLPSX de SQL para PowerShell en todos mis PowerShell scripts de base de datos. Hay algunas líneas en el […]

Read More

PowerShell – The Automator (T-SQL Tuesday #15)

Sal Young | February 8th, 2011


I read about T-SQL Tuesday #15 this evening while riding the train on my way home; I need to get in the scoop of these events when they first come out. How to Review SQL Logs with PoweShell describes one of the many scripts I created in PoweShell to automate my daily tasks. I have […]

Read More

Cómo Cambiar la Extensión de Todos los Archivos en un Directorio

Sal Young | February 7th, 2011


PROBLEMA: Tienes un directorio con muchos archivos y deseas cambiarles la extensión sin tener que hacerlo uno a uno. SOLUCION: Puedes lograr tu objetivo utilizando PowerShell y hacerlo con 3 líneas de código. CLEAR CD [PATH TO FILE LOCATION] Get-ChildItem *.[FILE EXTENSION]|Rename-Item –NewName {$_.Name –replace “[FROM VALUE]”,”[TO VALUE]”} Siempre me gusta empezar mis scripts con […]

Read More

How to Review SQL Logs with PowerShell

Sal Young | October 7th, 2010


PROBLEM: You need an easy way to review the MS SQL Server logs of all the servers you manage. SOLUTION: Use the Get-SqlErrorLog function from the SQL Server PowerShell Extensions (SQLPSX). I will show you some of the things you can achieve with the use of the Get-SqlErrorLog function and a bit of creativity.  We […]

Read More