When I first saw PowerShell, at TechEd 2006 (ish) and I was enamored. This was a much better environment than VBScript for working in a shell. Then I realized I needed -eq, -gt, etc. and was less excited. These language elements felt like a step back. Then I tried to build a restore script for SQL Server databases early on and was much less excited.
Across the years, I've played with various tasks in PoSh as opposed to T-SQL or simple command scripts in various languages, and I find myself going back and forth. PoSh is very useful in some ways, more cumbersome in others, and I still am not sure exactly how I feel about it as a go-to tool. I am coming around to use more PoSh because of the dbatools project, and I find myself considering PoSh instead of T-SQL, especially when I think I may want to work across instances and string together commands.
Recently I saw the DBAfromtheCold write a short piece on why you should learn PoSh. It's a good look at some of the tasks that are easy through PowerShell. Some of these could be done in T-SQL, some with other scripts, but PoSh certainly is a possibility and an easy way to manage some of the tasks you might need to do at scale.
I don't think PoSh is the best way to do everything. In fact, I often still lean on T-SQL for many admin things, especially if I already have a connection open in SSMS. However, as I learn more about PoSh and how to use it, I can make those judgment calls about when it's a better fit. That knowledge helps me become a more capable and stronger data professional, because I have choices about how to work with systems, and I have some knowledge or basis for the decisions I make.
I advocate continuing to learn throughout your career, and certainly including PoSh as a topic if you work on the Microsoft platforms.
Write, format, and refactor SQL effortlessly with SQL Prompt
Writing SQL is 50% faster with SQL Prompt. Your SQL code can be formatted just the way you like it, you can create and share snippets with your team, and with tab coloring you’ll never deploy to the wrong environment again. Download your free trial
Computing an average over all your data is easy, but what if your data arrives incrementally and you need to be able to compute real-time averages on the fly? That's what we are going to look at. More »
By default, SQL Prompt shows code auto-completion suggestions automatically, and continuously. 90% of the time this is exactly what you want, but there are other times where you just need a bit of space - Phil Factor shows how. More »
Expert T-SQL Window Functions in SQL Server takes you from any level of knowledge of windowing functions and turns you into an expert who can use these powerful functions to solve many T-SQL queries. Replace slow cursors and self-joins with queries that are easy to write and fantastically better performing, all through the magic of window functions. Get your copy from Amazon today.
Yesterday's Question of the Day
(by Steve Jones):
When logically processing a query, which of these filtering operations takes place last?
- Hi All,
I am using SQL below to get the object dependency.
select Obj.name,dep.referenced_entity_name from sys.sql_modules as Module,sys.objects AS Obj ,sys.sql_expression_dependencies
select from flat file
- How do select from a flat file?
FROM OPENROWSET(BULK 'C:\Test.txt' ,
FORMATFILE='C:\Test.txt') AS Test
WHERE Field1 <> 'N/A'
insert from flat file
- How do you insert data into a table variable from a flat file?
DECLARE @Format TABLE
BULK INSERT @Format
How can this query be rewitten?
- Hi Experts,
I have written a query based on our requirement using co-related sub-query.
Checking if this can re-written using...
This newsletter was sent to you because you signed up at SQLServerCentral.com.
Feel free to forward this to any colleagues that you think might be interested.
If you have received this email from a colleague, you can register to receive it here.