Skip to content

Fixed Get-SQLServerLoginDefaultPw failure where multiple credentials are present #44

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

Merged
merged 2 commits into from
Mar 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 28 additions & 22 deletions PowerUpSQL.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15025,29 +15025,35 @@ Function Get-SQLServerLoginDefaultPw
return
}

# Grab username and password
$CurrentUsername = $TblResultsTemp.username
$CurrentPassword = $TblResultsTemp.password

# Test login
$LoginTest = Get-SQLServerInfo -Instance $instance -Username $CurrentUsername -Password $CurrentPassword -SuppressVerbose
if($LoginTest){

Write-Verbose "$Instance : Confirmed default credentials - $CurrentUsername/$CurrentPassword"

$SysadminStatus = $LoginTest | select IsSysadmin -ExpandProperty IsSysadmin

# Append if successful
$TblResults.Rows.Add(
$ComputerName,
$Instance,
$CurrentUsername,
$CurrentPassword,
$SysadminStatus
) | Out-Null
}else{
Write-Verbose "$Instance : No credential matches were found."
}
#Write-Verbose ($instance).ToString()
#Write-Verbose ($CurrentUsername).ToString()
#Write-Verbose ($CurrentPassword).ToString()

# Grab and iterate username and password
for($i=0; $i -lt $TblResultsTemp.count; $i++){
#Write-Verbose $TblResultsTemp
$CurrentUsername = $TblResultsTemp.username[$i]
$CurrentPassword = $TblResultsTemp.password[$i]
$LoginTest = Get-SQLServerInfo -Instance $instance -Username $CurrentUsername -Password $CurrentPassword -SuppressVerbose
if($LoginTest){

Write-Verbose "$Instance : Confirmed default credentials - $CurrentUsername/$CurrentPassword"

$SysadminStatus = $LoginTest | select IsSysadmin -ExpandProperty IsSysadmin

# Append if successful
$TblResults.Rows.Add(
$ComputerName,
$Instance,
$CurrentUsername,
$CurrentPassword,
$SysadminStatus
) | Out-Null
}else{
Write-Verbose "$Instance : No credential matches were found."
}
}
}

End
Expand Down