Welcome to Day 18 of my “A Month of PowerShell” series. This series will use the series landing page on this blog at http://blog.waynesheffield.com/wayne/a-month-of-powershell/. Please refer to this page to see all of the posts in this series, and to quickly go to them.

Continuing the mini-series of objects compiled with T-SQL code, today we will work with stored procedures.

Creating a stored procedure

What would you think the difference is between creating a view and a stored procedure? For a simple stored procedure (without parameters), it’s just changing the class to StoredProcedure:

[codesyntax lang=”powershell” strict=”yes”]

[/codesyntax]

Creating a stored procedure with parameters

Creating a stored procedure with parameters changes the way that you need to create the procedure – specifically you need to specify the parameters. So, let’s create a procedure with both input and output parameters:

[codesyntax lang=”powershell” strict=”yes”]

[/codesyntax]

Altering and dropping stored procedures

Altering and dropping stored procedures are similar to what we did yesterday when altering and dropping views. Verify that the procedure does exist, and set the new procedure code in the TextBody parameter. If necessary, add / drop parameters, then call the procedures ALTER method. To drop, just call the DROP method after verifying that the procedure exists.