hand over switches in a variable for cmdlet get-dbadatabase

Julian 21 Reputation points
2022-04-27T15:15:34.27+00:00

Hi,
Is there a way to hand over the switches "Database" and "ExcludeDatabase" in a variable to get-DbaDatabase?

The following does not work:
$Instance = 'localhost'
$SelectedDatabases = 'master','model','msdb','tempdb'
$ExcludeOrIncludeDBs = 'ExcludeDatabase'
$Databases = Get-DbaDatabase -SqlInstance $Instance -$ExcludeOrIncludeDBs $SelectedDatabases | foreach {$_.Name}

Instead a login window appears and Username shows "-ExcludeDatabase"

BR
Julian

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2022-04-27T18:51:11.817+00:00

    That's possible if your 3rd-party software allows the use of "splatting" to provide the parameters and switches to that cmdlet.

    Try it this way. If it works, that's great. If it doesn't, contact the company supplying the package and request an improvement.

    $Instance = 'localhost'
    $SelectedDatabases = 'master','model','msdb','tempdb'
    $props = @{
        SqlInstance = $Instance
        ExcludeDatabase = $SelectedDatabases
    }
    $Databases = Get-DbaDatabase @props | foreach {$_.Name}
    
    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.