Skip to content

Commit ebe780f

Browse files
author
unknown
committed
Fixed Get-SQLServerLoginDefaultPw failure where multiple credentials are present
1 parent ce21102 commit ebe780f

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

PowerUpSQL.ps1

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15026,28 +15026,38 @@ Function Get-SQLServerLoginDefaultPw
1502615026
}
1502715027

1502815028
# Grab username and password
15029-
$CurrentUsername = $TblResultsTemp.username
15030-
$CurrentPassword = $TblResultsTemp.password
15029+
#Write-Verbose $TblResultsTemp
15030+
#$CurrentUsername = $TblResultsTemp.username
15031+
#$CurrentPassword = $TblResultsTemp.password
1503115032

1503215033
# Test login
15033-
$LoginTest = Get-SQLServerInfo -Instance $instance -Username $CurrentUsername -Password $CurrentPassword -SuppressVerbose
15034-
if($LoginTest){
15035-
15036-
Write-Verbose "$Instance : Confirmed default credentials - $CurrentUsername/$CurrentPassword"
15037-
15038-
$SysadminStatus = $LoginTest | select IsSysadmin -ExpandProperty IsSysadmin
15039-
15040-
# Append if successful
15041-
$TblResults.Rows.Add(
15042-
$ComputerName,
15043-
$Instance,
15044-
$CurrentUsername,
15045-
$CurrentPassword,
15046-
$SysadminStatus
15047-
) | Out-Null
15048-
}else{
15049-
Write-Verbose "$Instance : No credential matches were found."
15050-
}
15034+
#Write-Verbose ($instance).ToString()
15035+
#Write-Verbose ($CurrentUsername).ToString()
15036+
#Write-Verbose ($CurrentPassword).ToString()
15037+
15038+
# Grab and iterate username and password
15039+
for($i=0; $i -lt $TblResultsTemp.count; $i++){
15040+
$CurrentUsername = $TblResultsTemp.username[$i]
15041+
$CurrentPassword = $TblResultsTemp.password[$i]
15042+
$LoginTest = Get-SQLServerInfo -Instance $instance -Username $CurrentUsername -Password $CurrentPassword -SuppressVerbose
15043+
if($LoginTest){
15044+
15045+
Write-Verbose "$Instance : Confirmed default credentials - $CurrentUsername/$CurrentPassword"
15046+
15047+
$SysadminStatus = $LoginTest | select IsSysadmin -ExpandProperty IsSysadmin
15048+
15049+
# Append if successful
15050+
$TblResults.Rows.Add(
15051+
$ComputerName,
15052+
$Instance,
15053+
$CurrentUsername,
15054+
$CurrentPassword,
15055+
$SysadminStatus
15056+
) | Out-Null
15057+
}else{
15058+
Write-Verbose "$Instance : No credential matches were found."
15059+
}
15060+
}
1505115061
}
1505215062

1505315063
End

0 commit comments

Comments
 (0)