Open van-thieu opened 7 months ago
Hi @van-thieu, that is not supported (at least today).
Have you considered something like:
$Database = Get-SqlDatabase -ServerInstance $Server -Name $Name
$Database | % { Push-Location (Convert-UrnToPath $_.Urn); Invoke-Sqlcmd -Query "Insert Into..." -SuppressProviderContextWarning; Pop-Location }
or
$Database = Get-SqlDatabase -ServerInstance $Server -Name $Name
$Database.Parent | Invoke-Sqlcmd -Query '...' -Database $Database.Name
I suppose I could make the cmdlet a little bit more tolerant and accept a SMO Database object (the type returned by Get-SqlDatabase
) and not just SMO Server or string.
The "problem" is that today we are stuck with -ServerInstance
being the argument from the pipeline... and changing that would be a breaking change for many people.
Perhaps, we could just keep the -ServerInstance
name as it is and accept the database object as well. or something like that... it would be a bit (or a lot) confusing though...
Thanks. Hopefully, it could be more dynamic in the future.
Is it possible to do the below?
$Database = Get-SqlDatabase -ServerInstance $Server -Name $Name
$Database | Invoke-Sqlcmd -Query "Insert Into..."