Category: PowerShell

How to Script All Stored Procedures From a Database with PowerShell

Sal Young | September 10th, 2010


PROBLEM: You need to script all stored procedures from a database.  Each stored procedure needs to be on its own file so you can add them to a source control repository. SOLUTION: The solution here is a variation of what we did for “How to Script All Tables From a Database with PowerShell”.  The only difference […]

Read More

How to Script All Tables From a Database with PowerShell

Sal Young | August 22nd, 2010


PROBLEM: You need to script all the tables from a database.  Each table needs to be on its own file so they can be added to a source control repository. SOLUTION: The use of SQL Server PowerShell Extensions (SQLPSX) facilitates the solution I’m about to show. The first example is a straight to the point, […]

Read More

How to Change File Extension for all Files in a Folder

Sal Young | August 21st, 2010


PROBLEM: You have a directory with many files and would like to change the extension on many of them without having to do one by one. SOLUTION: You can solve this problem with PowerShell and in less than 3 lines of code. CLEAR CD [PATH TO FILE LOCATION] Get-ChildItem *.[FILE EXTENSION]|Rename-Item –NewName {$_.Name –replace “[FROM […]

Read More

Review SQL Server 2008 Administration with Windows Powershell

Sal Young | February 21st, 2010


I recommend this book to all database administrators who still have not jumped in and executed their first PowerShell command.  I know of several DBAs who for one excuse reason or another, keep postponing their exposure to the next generation command line shell.  This volume makes a good first PowerShell book for DBAs.  It covers […]

Read More

Monitoring MS SQL Jobs with PowerShell

Sal Young | July 14th, 2009


PROBLEM: You manage many MS SQL servers and need an easy way to review jobs that have failed. SOLUTION: I will show you one way to accomplish this task with results displaying on the screen or to a file. To make your life easier, I recommend you download & install PowerGUI from Quest Software. This […]

Read More

Scan network for instances of MS SQL with Powershell

Sal Young | February 24th, 2009


PROBLEM: You need to find out which computers and servers in my network have an instance of MS SQL installed. SOLUTION: In this solution we’ll create an instance of the Windows Management Instrumentation (WMI) for each computer in a list. We’ll then query the Win32_Service class for the existence of a service which name starts […]

Read More

How to Script Database Tables with PowerShell

Sal Young | February 20th, 2009


PROBLEM: I need an easy way to script out all the tables from a database in MS SQL 2000 and above. SOLUTION: Like anything in programming, there are a thousand ways to skin a cat. Here, I’ll show you the simplest way I found to meet this request. Go ahead and open a new session […]

Read More

WMI Date Conversion

Sal Young | July 6th, 2005


USE: To convert the GMT data returned from error logs to a readable date time value. CLEAR $sHostName = “TUIRA” $aLogName = “Application” $FromDate = [datetime]::today $WMIQuery = “LogFile=’$aLogName’ and Type=’Error’ and TimeGenerated>=’$FromDate'” Get-WmiObject Win32_NTLogEvent -ComputerName $sHostName ` -Filter “$WMIQuery” ` -ErrorAction SilentlyContinue | ` SELECT SourceName, ` @{Name = “TimeGenerated”; EXPRESSION = {$_.ConvertToDateTime($_.TimeGenerated)}}, ` […]

Read More

PowerShell and Outlook

Sal Young | June 27th, 2005


This script was written by ed wilson at Use PowerShell to Data Mine Your Outlook Inbox CLEAR Function Get-OutlookInBox { Add-type -assembly “Microsoft.Office.Interop.Outlook” | out-null $olFolders = “Microsoft.Office.Interop.Outlook.olDefaultFolders” -as [type] $outlook = new-object -comobject outlook.application $namespace = $outlook.GetNameSpace(“MAPI”) $folder = ($namespace.getDefaultFolder($olFolders::olFolderInBox)).folders|WHERE {$_.Name -eq “DDUMP”} $folder.items | Select-Object -Property Subject, ReceivedTime, Importance, SenderName } #end function […]

Read More