Powershell parameters

  • Comments posted to this topic are about the item Powershell parameters

  • Thank you, Steve, for the post (a different kind, break from SQL for a day). This was very easy for me.

    ww; Raghu
    --
    The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.

  • Great question, definately learned something.

    With all those programming languages, you never know if an array is zero based or not. 🙂

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • This was removed by the editor as SPAM

  • Heh... for me, the correct answer isn't available, which is "Don't worry about it because if it's to do something in SQL, then it's likely that you're using the wrong tool to begin with. Learn SQL." 😉

    --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)

  • Jeff Moden (2/6/2015)


    Heh... for me, the correct answer isn't available, which is "Don't worry about it because if it's to do something in SQL, then it's likely that you're using the wrong tool to begin with. Learn SQL." 😉

    Isn't this SQL?!:-D xp_cmdshell '...'

  • Thanks for this simple question. I had only to remember my 1st tests with PowerShell 6 years ago. I guess easily that the last proposal was not the good one. As I knew that the order of parameters was beginning to 0 , the "good answer" was evident.

    But it was useful as I have not used SQLPS since 2 years ( I am not feeling easy with this tool ... )

  • Nice and easy. Particularly nice to see that I'm not the only old dinosaur left still using $args.

    But maybe a bit old-fashioned.

    I would use $args[0] because I've been doing that in other languages for longer than I can remember (well, at least since I first got my hands on a Unix box).

    But I've been told by powershell experts (who shall be nameless, to protect the idiots innocent, that you shouldn't do that any more, they've put all this clever naming and reodering stuff into the interpreter, and all parameters should be named even if you only have one, so instead of $args[0] it should be some suitable name, perhaps $theonlyargument, and you should have a param statement, perhaps

    param( [string]theonlyargument = $(throw "-theonlyargument is required" )

    to define that name.

    Since the only reason for parameter naming is to allow the user use parameter names to supply parameters in a different order, or to define defaults so that the user can choose which parameters to supply, and since even with hordes of parameters all that requires only the param statement, not use of param names in the script body (since the param statement defines the parameter order, ie the index of each parameter within $args), I think saying you have to refer to an only parameter by name inside the script is a load of codswallop would be a warrantless imposition on the script writer, but then I'm not a powerscript expert.

    Tom

  • Just remember that it is zero based and all is well.

  • Mighty (2/6/2015)


    Jeff Moden (2/6/2015)


    Heh... for me, the correct answer isn't available, which is "Don't worry about it because if it's to do something in SQL, then it's likely that you're using the wrong tool to begin with. Learn SQL." 😉

    Isn't this SQL?!:-D xp_cmdshell '...'

    I don't use xp_CmdShell to do things like backups (except maybe to delete old files and that's a rare exception), rebuilding indexes, doing health checks, etc, etc, like many do with PoSH. 😉

    --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)

  • Jeff Moden (2/11/2015)


    Mighty (2/6/2015)


    Jeff Moden (2/6/2015)


    Heh... for me, the correct answer isn't available, which is "Don't worry about it because if it's to do something in SQL, then it's likely that you're using the wrong tool to begin with. Learn SQL." 😉

    Isn't this SQL?!:-D xp_cmdshell '...'

    I don't use xp_CmdShell to do things like backups (except maybe to delete old files and that's a rare exception), rebuilding indexes, doing health checks, etc, etc, like many do with PoSH. 😉

    As well as deleting old files, I used to use it to get directory listings - "dir ...." seemed a reasonable bit to include in the argument string.

    Tom

  • +1 Thanks for the nice question.

    Andre Ranieri

Viewing 12 posts - 1 through 11 (of 11 total)

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