diff --git a/public/Set-DbaDbOwner.ps1 b/public/Set-DbaDbOwner.ps1 index 37f06bb93b..452794d397 100644 --- a/public/Set-DbaDbOwner.ps1 +++ b/public/Set-DbaDbOwner.ps1 @@ -87,6 +87,7 @@ function Set-DbaDbOwner { [string]$TargetLogin, [switch]$EnableException ) + process { if (-not $InputObject -and -not $SqlInstance) { Stop-Function -Message "You must pipe in a database or specify a SqlInstance" @@ -94,14 +95,7 @@ function Set-DbaDbOwner { } if ($SqlInstance) { - $getDbParams = @{ - SqlInstance = $SqlInstance - SqlCredential = $SqlCredential - Database = $Database - ExcludeDatabase = $ExcludeDatabase - EnableException = $EnableException - } - $InputObject += Get-DbaDatabase @getDbParams + $InputObject += Get-DbaDatabase -SqlInstance $SqlInstance -SqlCredential $SqlCredential -Database $Database -ExcludeDatabase $ExcludeDatabase } foreach ($db in $InputObject) { @@ -109,7 +103,7 @@ function Set-DbaDbOwner { if ($db.IsSystemObject) { continue } - if (-not $db.IsAccessible) { + if (!$db.IsAccessible) { Write-Message -Level Warning -Message "Database $db is not accessible. Skipping." continue } @@ -128,7 +122,7 @@ function Set-DbaDbOwner { } #Owner cannot be a group - $TargetLoginObject = $server.Logins | Where-Object { $PSItem.Name -eq $TargetLogin } | Select-Object -Property Name, LoginType + $TargetLoginObject = $server.Logins | Where-Object { $PSItem.Name -eq $TargetLogin } | Select-Object -property Name, LoginType if ($TargetLoginObject.LoginType -eq 'WindowsGroup') { Stop-Function -Message "$TargetLogin is a group, therefore can't be set as owner. Moving on." -Continue -EnableException $EnableException }