Forum Discussion
New to PowerShell, but not programming. very confused
- Sep 03, 2022
Yes, your screenshot showing "what you get" makes perfect sense.
As noted in the commandlet's documentation, Invoke-Sqlcmd returns one of the following types (see the OutputAs parameter description for these details):
- DataRows ([System.Data.DataRow])
- DataSet ([System.Data.DataSet])
- DataTables ([System.Data.DataTable])
If you don't specify the -OutputAs parameter, then you get DataTables by default - which is what you see in your screenshot.
If you cross-reference that with your script, here are the points of interest:
- Line 5: An integer value of 0 is assigned to the variable $seqnew, which ends up never being used because:
- Line 6: A new value of type [System.Data.DataTable] is assigned to $seqnew from the output of Invoke-Sqlcmd;
- Line 34: $seqnew, which is still of type [System.Data.DataTable] is included in the formatted string, probably under the assumption it's an integer when it's not.
This is why your screenshot is telling you $seqnew is a [System.Data.DataTable], because as of line 6, that's what it has become.
Cheers,
Lain
Yes, your screenshot showing "what you get" makes perfect sense.
As noted in the commandlet's documentation, Invoke-Sqlcmd returns one of the following types (see the OutputAs parameter description for these details):
- DataRows ([System.Data.DataRow])
- DataSet ([System.Data.DataSet])
- DataTables ([System.Data.DataTable])
If you don't specify the -OutputAs parameter, then you get DataTables by default - which is what you see in your screenshot.
If you cross-reference that with your script, here are the points of interest:
- Line 5: An integer value of 0 is assigned to the variable $seqnew, which ends up never being used because:
- Line 6: A new value of type [System.Data.DataTable] is assigned to $seqnew from the output of Invoke-Sqlcmd;
- Line 34: $seqnew, which is still of type [System.Data.DataTable] is included in the formatted string, probably under the assumption it's an integer when it's not.
This is why your screenshot is telling you $seqnew is a [System.Data.DataTable], because as of line 6, that's what it has become.
Cheers,
Lain
- MNtobarSep 06, 2022Copper Contributor
Thanks,LainRobertson
“Everything works the way it is supposed to, even when it isn’t what you expect.” -- Gyro Gearloose (attributed) 😊
Your reply was gracious, instructional and very much appreciated. If have been in environments where the reply would have been laced with derision and the (usually) unhelpful statement of "RTFM!!"
I had looked at the referred to documentation. My background caused me to expect the “Inputs” and “Outputs” sections to be the first items on a doc page. I gave up after reading through all the non-Azure examples and scrolling through several pages of parameters. I should have persevered and read closer. Thanks.
Tobar