Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-SqlDatabase and Invoke-Sqlcmd Piping #63

Open
van-thieu opened this issue Nov 8, 2023 · 2 comments
Open

Get-SqlDatabase and Invoke-Sqlcmd Piping #63

van-thieu opened this issue Nov 8, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@van-thieu
Copy link

Is it possible to do the below?

$Database = Get-SqlDatabase -ServerInstance $Server -Name $Name

$Database | Invoke-Sqlcmd -Query "Insert Into..."

@Matteo-T Matteo-T self-assigned this Nov 16, 2023
@Matteo-T
Copy link
Collaborator

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...

@van-thieu
Copy link
Author

Thanks.
Hopefully, it could be more dynamic in the future.

@Matteo-T Matteo-T added the enhancement New feature or request label Jun 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants