A demo about the power of powershell

  • Comments posted to this topic are about the item A demo about the power of powershell

  • Lovely! Tasks get easier everyday.

    I have never use PowerShell though. Can you please tell me the resources that I need to get started on PowerShell. Thanks

  • Best way to learn Powershell is Bruce Payette's book: PowerShell in Action. First edition is just fine, second covers remoting as well.

    But Daniel, why do you use "echo $var" to output something in Powershell? It's way nicer to just tell that whatever the evaluation result is the output. So $var in itself will print out the variable.

    Cheers,

    Erik

  • Thanks for posting a basic Powershell article. Most Powershell articles I've read assume that I already know most of how it works - but I don't because I haven't started using it. I tried your demo on my dev server and was happy to see it work. 😀

  • What I like about powershell is that Linux and Unix users can also play with it like they were at home. That's why I used the echo. There are many alias that can help to linux users to learn PS easily.

  • Though its great all the features of powershell for all of MS's offerings. It still makes me feel like they are unfinished products or features. Where 'gui'ed features appear more tested in a variety of environments.

  • Yes, I believe that powershell will progress a lot in the future.

  • Excellent article Daniel. You showed in simple steps how useful powershell can be.

    M&M

  • Gosh... I'm torn. This article is really a nice simple article on how to loop in powershell and probably should have been advertised that way. On the other hand, it shows a disturbing trend.

    Powershell is becoming just like Cursors, Recursive CTEs, and CLR. It's the next "cool thing" and everyone is going to demo it with and use it for things they really shouldn't. As the saying goes, just because something can be done a certain way, doesn't mean it should.

    I also think it's odd that we've come full circle. It used to be that people complained about having to maintain things by script instead of by GUI and now the opposite is becoming true. People with straight hair want curly hair and people with curly hair want straight hair. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Yeah I'm kind of torn about this. It's an indicative demonstration I guess.

    There's no denying that for scripts that need to do automated and extremely nifty things, powershell is probably the future. Creating databases is not really one of those things though. You still have to go and modify all necessary settings on each database from their server default, like a good DBA. Yes you could probably do all that in PS too, but why when there's SSMS?

  • Hi all,

    When I run $list | ForEach-Object {Invoke-SqlCmd -Query "create database $_"}

    I get:

    The term 'invoke-sqlcmd' is not recognized as the name of a cmdlet, function, s

    cript file, or operable program. Check the spelling of the name, or if a path w

    as included, verify that the path is correct and try again.

    At line:1 char:38

    + $list | ForEach-Object (invoke-sqlcmd <<<< -Query "create database $_")

    + CategoryInfo : ObjectNotFound: (invoke-sqlcmd:String) [], Comma

    ndNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException

    What am I doing wrong???, maybe Powershell version?? Mine is 1.0

    Regards.

  • Jeff Moden (3/25/2012)


    Powershell is becoming just like Cursors, Recursive CTEs, and CLR. It's the next "cool thing" and everyone is going to demo it with and use it for things they really shouldn't. As the saying goes, just because something can be done a certain way, doesn't mean it should.

    I also think it's odd that we've come full circle. It used to be that people complained about having to maintain things by script instead of by GUI and now the opposite is becoming true. People with straight hair want curly hair and people with curly hair want straight hair. 😉

    On what aspects you recommend using Powershell in SQL Server? I am little confused with your comments.

    Could you please throw some light, it would be great for Powershell newbies to hear from you 🙂

    M&M

  • carl_corpus (3/26/2012)


    Hi all,

    When I run $list | ForEach-Object {Invoke-SqlCmd -Query "create database $_"}

    I get:

    The term 'invoke-sqlcmd' is not recognized as the name of a cmdlet, function, s

    cript file, or operable program. Check the spelling of the name, or if a path w

    as included, verify that the path is correct and try again.

    At line:1 char:38

    + $list | ForEach-Object (invoke-sqlcmd <<<< -Query "create database $_")

    + CategoryInfo : ObjectNotFound: (invoke-sqlcmd:String) [], Comma

    ndNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException

    What am I doing wrong???, maybe Powershell version?? Mine is 1.0

    Regards.

    Try running this inside SQLPS.

    i.e after you go to powershell console, type SQLPS and then follow the steps as described by Daniel.

    M&M

  • mohammed moinudheen (3/26/2012)


    Jeff Moden (3/25/2012)


    Powershell is becoming just like Cursors, Recursive CTEs, and CLR. It's the next "cool thing" and everyone is going to demo it with and use it for things they really shouldn't. As the saying goes, just because something can be done a certain way, doesn't mean it should.

    I also think it's odd that we've come full circle. It used to be that people complained about having to maintain things by script instead of by GUI and now the opposite is becoming true. People with straight hair want curly hair and people with curly hair want straight hair. 😉

    On what aspects you recommend using Powershell in SQL Server? I am little confused with your comments.

    Could you please throw some light, it would be great for Powershell newbies to hear from you 🙂

    I'd use powershell for things that can't be done in SQL Server. Things like "auto-discovery" of servers and doing hard-disk "audits" on them to make sure they're not running out of space or for things that require the interogation of Active Directory, etc. Just like with CLR, there are a ton of things that SQL Server either can't do or isn't very good at doing that powershell could be used for. I agree that this article was mostly about a simple looping example and for that purpose it was great. I just hope that no one thinks that using powershell to create multiple databases in an ongoing basis is a good thing. It could be a good thing if you're building an "installation script" for a product, though. As always, "It Depends".

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Yes, powershell for SQL Server was included in SQL Server 2008. It was the sqlps. In SQL 2012, the powershell 2.0 includes de SQL command and it is not a separated application anymore.

Viewing 15 posts - 1 through 15 (of 18 total)

You must be logged in to reply to this topic. Login to reply