Skip to content

Commit a2cb2ee

Browse files
authored
Merge pull request #44 from YinjiDawn/bugfix-multiple-credentials
Fixed Get-SQLServerLoginDefaultPw failure where multiple credentials are present
2 parents 9923d9b + 86f917d commit a2cb2ee

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

PowerUpSQL.ps1

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15165,29 +15165,35 @@ Function Get-SQLServerLoginDefaultPw
1516515165
return
1516615166
}
1516715167

15168-
# Grab username and password
15169-
$CurrentUsername = $TblResultsTemp.username
15170-
$CurrentPassword = $TblResultsTemp.password
15171-
1517215168
# Test login
15173-
$LoginTest = Get-SQLServerInfo -Instance $instance -Username $CurrentUsername -Password $CurrentPassword -SuppressVerbose
15174-
if($LoginTest){
15175-
15176-
Write-Verbose "$Instance : Confirmed default credentials - $CurrentUsername/$CurrentPassword"
15177-
15178-
$SysadminStatus = $LoginTest | select IsSysadmin -ExpandProperty IsSysadmin
15179-
15180-
# Append if successful
15181-
$TblResults.Rows.Add(
15182-
$ComputerName,
15183-
$Instance,
15184-
$CurrentUsername,
15185-
$CurrentPassword,
15186-
$SysadminStatus
15187-
) | Out-Null
15188-
}else{
15189-
Write-Verbose "$Instance : No credential matches were found."
15190-
}
15169+
#Write-Verbose ($instance).ToString()
15170+
#Write-Verbose ($CurrentUsername).ToString()
15171+
#Write-Verbose ($CurrentPassword).ToString()
15172+
15173+
# Grab and iterate username and password
15174+
for($i=0; $i -lt $TblResultsTemp.count; $i++){
15175+
#Write-Verbose $TblResultsTemp
15176+
$CurrentUsername = $TblResultsTemp.username[$i]
15177+
$CurrentPassword = $TblResultsTemp.password[$i]
15178+
$LoginTest = Get-SQLServerInfo -Instance $instance -Username $CurrentUsername -Password $CurrentPassword -SuppressVerbose
15179+
if($LoginTest){
15180+
15181+
Write-Verbose "$Instance : Confirmed default credentials - $CurrentUsername/$CurrentPassword"
15182+
15183+
$SysadminStatus = $LoginTest | select IsSysadmin -ExpandProperty IsSysadmin
15184+
15185+
# Append if successful
15186+
$TblResults.Rows.Add(
15187+
$ComputerName,
15188+
$Instance,
15189+
$CurrentUsername,
15190+
$CurrentPassword,
15191+
$SysadminStatus
15192+
) | Out-Null
15193+
}else{
15194+
Write-Verbose "$Instance : No credential matches were found."
15195+
}
15196+
}
1519115197
}
1519215198

1519315199
End

0 commit comments

Comments
 (0)