how to use variable for Invoke-Sqlcmd -ServerInstance This topic contains 1 reply, has 2 voices, and was last updated by Dave Wyatt 1 year, 7 months ago. Author Posts April 1, 2016 at 8:59 am #37160 Kir KParticipant Hi all! Have a question on how to pipe/use variable in Invoke-Sqlcmd -ServerInstance. Usecase: working on script which runs some SQL code for SQLServer\Instance, but they are different most of the time. I can retrieve SQLServer Instance as System.Strings but can not pipe to the command. Set-location sqlserver:\sql\ doesn't accept variables too Invoke-Sqlcmd -ServerInstance $a.SqlServerName\$b.SQLInstanceName -Query "SELECT @@VERSION" April 1, 2016 at 9:07 am #37161 Dave WyattModerator You'll need to use subexpression operators to get the behavior you're after: Invoke-Sqlcmd -ServerInstance "$($a.SqlServerName)\$($b.SQLInstanceName)" -Query "SELECT @@VERSION" Author Posts You must be logged in to reply to this topic.