我有一个问题,我找不到...
我希望将SQL脚本的返回值返回到Powershell。
-MyScript.sql
DECLARE @var VARCHAR(20);
SET @var = 'databaseName';
-我的PowerShell
$serverInstance='Server'
$inputFile='C:\Users\xxx\Desktop\xxx\MyScript.sql'
$user='user'
$pass='pass'
$splat=@{
ServerInstance=$serverInstance
InputFile=$InputFile
U=$user
P=$pass
}
$result= @(Invoke-Sqlcmd @splat -ErrorAction Stop)
#From here it's an example because don't know how
$result= @var #The return from .SQL Script @var = 'databaseName'
If $result = "databaseName"
#Invoke-Sqlcmd with other actions
帮助!