Skip to main content
removed tag from subject, improved formatting, removed fluff
Source Link
Ansgar Wiechers
  • 199.8k
  • 26
  • 280
  • 354

Getting SQL value from sqlcmd.exe remotely [Powershell]

iI should execute remotely SQL command on dataBasedatabase because sqlsqlcmd is not installed.

$Configuration = Invoke-Command `

            -ComputerName $dataserverName `

            -Credential $cred `

            -ScriptBlock {
 
                sqlcmd.exe -S $using:dataserver -U $using:user -P $using:pass -d $using:database -q $using:SQLQuery
 
            }

So when iI execute my request, iI got the response in the same block so iI can not get value from each column like this  :

MinimumSize          MaximumSize          Delimiter             IdFile

            NULL                 NULL          |                   6

MinimumSize          MaximumSize          Delimiter             IdFile
-------------------- -------------------- --------- ----------------------
                NULL                 NULL         |                   6

(1 rows affected)

(1 rows affected)

so if iI do $Configuration[0] $Configuration[0], iI got

$Configuration[0] = MinimumSize          MaximumSize          Delimiter             IdFile

like a line, so iI can not do anything. My question is how to get for example $Configuration.IdFile = 6

thanks in advance$Configuration.IdFile = 6.

Getting SQL value from sqlcmd.exe remotely [Powershell]

i should execute remotely SQL command on dataBase because sql is not installed.

$Configuration = Invoke-Command `

            -ComputerName $dataserverName `

            -Credential $cred `

            -ScriptBlock {
 
                sqlcmd.exe -S $using:dataserver -U $using:user -P $using:pass -d $using:database -q $using:SQLQuery
 
            }

So when i execute my request, i got the response in the same block so i can not get value from each column like this  :

MinimumSize          MaximumSize          Delimiter             IdFile

            NULL                 NULL          |                   6

(1 rows affected)

so if i do $Configuration[0] , i got

$Configuration[0] = MinimumSize          MaximumSize          Delimiter             IdFile

like a line, so i can not do anything. My question is how to get for example $Configuration.IdFile = 6

thanks in advance

Getting SQL value from sqlcmd.exe remotely

I should execute remotely SQL command on database because sqlcmd is not installed.

$Configuration = Invoke-Command -ComputerName $dataserverName -Credential $cred -ScriptBlock {
    sqlcmd.exe -S $using:dataserver -U $using:user -P $using:pass -d $using:database -q $using:SQLQuery
}

So when I execute my request, I got the response in the same block so I can not get value from each column like this:


MinimumSize          MaximumSize          Delimiter             IdFile
-------------------- -------------------- --------- ----------------------
                NULL                 NULL         |                   6

(1 rows affected)

so if I do $Configuration[0], I got

$Configuration[0] = MinimumSize          MaximumSize          Delimiter             IdFile

like a line, so I can not do anything. My question is how to get for example $Configuration.IdFile = 6.

Source Link
rx4i
  • 1
  • 3

Getting SQL value from sqlcmd.exe remotely [Powershell]

i should execute remotely SQL command on dataBase because sql is not installed.

$Configuration = Invoke-Command `

            -ComputerName $dataserverName `

            -Credential $cred `

            -ScriptBlock {

                sqlcmd.exe -S $using:dataserver -U $using:user -P $using:pass -d $using:database -q $using:SQLQuery

            }

So when i execute my request, i got the response in the same block so i can not get value from each column like this :

MinimumSize          MaximumSize          Delimiter             IdFile

            NULL                 NULL          |                   6

(1 rows affected)

so if i do $Configuration[0] , i got

$Configuration[0] = MinimumSize          MaximumSize          Delimiter             IdFile

like a line, so i can not do anything. My question is how to get for example $Configuration.IdFile = 6

thanks in advance