开发者

How to pass parameters to sqlps from a master windows powershell script

I have a master powershell script as follows. It defines a single variable $V1 and then launches the sqlps that uses this variable. Since sqlps is itself a minishell it does not recognise $V1

$V1 = "asdasd"    

sqlps -NoLogo -Command {
            invoke-sqlcmd -Query $V1 -ServerInstance "SomeImstamce" -Database "SomeDatabase" -Username "SomeUsernName" -Password "SomePassword"
      }

I therefore updated the sqlps -Command block to expect a parameter as follows. However I am not sure how to pass the outer $V1 variable value to the inner sqlps -Command Block

$V1 = "RBIQHSAPPD049v.b2b.regn.net"

sqlps -NoLogo -Command {
            param ($SqlPsParam)
            invoke-sqlcmd -Que开发者_开发百科ry $SqlPsParam  -ServerInstance "SomeImstamce" -Database "SomeDatabase" -Username "SomeUsernName" -Password "SomePassword"
      }

There is syntax help on http://technet.microsoft.com/en-us/library/cc280450.aspx and I have tried many combinations but it doesnot seem to work.

Any idea?


oh figure it out atlast

$V1 = "sdfsaf"
$V2 = "safd"

sqlps -NoLogo -Command {
            param ($SqlPsParam1, $SqlPsParam2)
            invoke-sqlcmd -Query $SqlPsParam  -ServerInstance "SomeImstamce" -Database "SomeDatabase" -Username "SomeUsernName" -Password "SomePassword"
      } -args $V1, $V2
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜