February 5, 2015 at 8:33 pm
Comments posted to this topic are about the item Powershell parameters
February 5, 2015 at 11:22 pm
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.
February 6, 2015 at 1:06 am
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
February 6, 2015 at 1:20 am
This was removed by the editor as SPAM
February 6, 2015 at 6:52 am
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
Change is inevitable... Change for the better is not.
February 6, 2015 at 8:47 am
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 '...'
February 6, 2015 at 11:22 am
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 ... )
February 6, 2015 at 12:45 pm
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
February 11, 2015 at 6:37 am
Just remember that it is zero based and all is well.
February 11, 2015 at 8:01 am
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
Change is inevitable... Change for the better is not.
February 14, 2015 at 2:30 pm
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
February 20, 2015 at 4:26 pm
+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