Skip to content

Commit

Permalink
revert Set-DdbaDbOwner
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Jun 27, 2023
1 parent 3db7742 commit 238a22b
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions public/Set-DbaDbOwner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -87,29 +87,23 @@ 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"
return
}

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) {
# Exclude system databases
if ($db.IsSystemObject) {
continue
}
if (-not $db.IsAccessible) {
if (!$db.IsAccessible) {
Write-Message -Level Warning -Message "Database $db is not accessible. Skipping."
continue
}
Expand All @@ -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
}
Expand Down

0 comments on commit 238a22b

Please sign in to comment.