我有一个主powershell脚本,如下所示。它定义了一个单一变量$V1,然后启动使用该变量的sqlps。由于sqlps本身是一种小型车,所以它不承认$V1。
$V1 = "asdasd"
sqlps -NoLogo -Command {
invoke-sqlcmd -Query $V1 -ServerInstance "SomeImstamce" -Database "SomeDatabase" -Username "SomeUsernName" -Password "SomePassword"
}因此,我更新了sqlps -Command块,希望得到如下参数。但是,我不知道如何将外部$V1变量值传递给内部sqlps -Command块。
$V1 = "RBIQHSAPPD049v.b2b.regn.net"
sqlps -NoLogo -Command {
param ($SqlPsParam)
invoke-sqlcmd -Query $SqlPsParam -ServerInstance "SomeImstamce" -Database "SomeDatabase" -Username "SomeUsernName" -Password "SomePassword"
}在http://technet.microsoft.com/en-us/library/cc280450.aspx上有语法帮助,我尝试过许多组合,但它似乎不起作用。
有什么想法吗?
发布于 2011-01-06 18:20:38
哦,最后想清楚
$V1 = "sdfsaf"
$V2 = "safd"
sqlps -NoLogo -Command {
param ($SqlPsParam1, $SqlPsParam2)
invoke-sqlcmd -Query $SqlPsParam -ServerInstance "SomeImstamce" -Database "SomeDatabase" -Username "SomeUsernName" -Password "SomePassword"
} -args $V1, $V2https://stackoverflow.com/questions/4618065
复制相似问题