Forum Discussion

MNtobar's avatar
MNtobar
Copper Contributor
Sep 02, 2022
Solved

New to PowerShell, but not programming. very confused

I have no idea what version of PowerShell I am running, but I am using Win10.   PowerShell newbie just trying to understand how things work. Many of years experience scripting SQL database stuff. ...
  • LainRobertson's avatar
    Sep 03, 2022

    MNtobar 

     

    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

Resources