PowerShell Week at SQL University – Post 5

You may also like...

8 Responses

  1. Tom Hoover says:

    Thanks for this intro to PowerShell and SQL Server. Over the past week I reviewed your material from last year as well as what you prepared for this semester. This opporuntity motivated me to actually begin focusing on adding Powershell as one of the tools in my DBA war chest. Due to your info I now realize that I have three ways to access powershell on my servers and how to use powershell for more than just a “dir” command. I am probably not even 1% proficient in it yet, but you have given me the tools to at least begin using the tools in a productive manner. Can’t wait for the week 2 later this semester.

  2. Tom Hoover says:

    I had to modify the Database Table/Query script to run on my system

    I changed the first $db after the first curly brace to be $db.name. Without adding the .name suffix I only received the listing of DB names. When I added the suffix I actually executed the embedded query.

    Sounds bizarre to me, but thats my story and I’m sticken to it.

    Any ideas?

    • Aaron Nelson says:

      Thanks for pointing that out to me; I have corrected that error. I explain the reason more in the next post but the short version of the difference is that $db means ‘give me the whole db [object] and everying that you know about it’ whereas $db.name means ‘Give me the contents of the “name” property of the $db object’.

  3. So, to make sure I understand the basic syntax of the foreach loop, it’s:

    foreach ($Variable in )


    Why don’t the last two loops have the “$Variable;” bit in there? Is that only required when using Invoke-SQLCmd?

    This is cool. I feel like I’m actually beginning to understand what I’m looking at. Thank you!

    • Aaron Nelson says:

      Oh, great question. It’s not required at all actually. I just put them in there to use as a PRINT statement to let you know where it was at. You can take them out if you like. I will be going over that in today’s post.

  4. Very cool. Since the CMS keeps a table ([msdb].[dbo].[sysmanagement_shared_registered_servers_internal]) with all the registered servers on it, can you use PowerShell to loop through that table in order to do stuff with it?

  1. 2011.01.20

    […] This post was mentioned on Twitter by Jorge Segarra, Jorge Segarra, SQL University, Aaron Nelson, SQL University and others. SQL University said: RT @SQLvariant: Better to squeak it in minutes before midnight than not at all: http://bit.ly/gw28oy #SQLU […]

  2. 2011.03.01

    […] […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: