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 -Query $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