PowerUpSQL icon indicating copy to clipboard operation
PowerUpSQL copied to clipboard

Fixed array logic for Get-SQLServerLoginDefaultPw

Open aredspyinthebase opened this issue 10 months ago • 0 comments

Bug introduced with original iteration PR to handle multiple credentials: https://github.com/NetSPI/PowerUpSQL/pull/44

Same effect as https://github.com/NetSPI/PowerUpSQL/pull/82,this version just uses a subexpression to ensure an array of objects is created.

When generating a matching table with Where-Object { $_.instance -eq "$TargetInstance"}, the script assumes it will always return an array of objects, which is not true if there's only one matching instance name, so the iteration and resulting login test will never run.

Further, the iteration over the table incorrectly accesses the username and password fields, so the resulting login check fails because it instead iterates through the string instead of the array.

The change adds a @() subexpression to ensure the $TblResultsTemp is an iteratable collection and moves the element access from $TblResultsTemp.username[$i] to TblResultsTemp[$i].username (same for password field).

aredspyinthebase avatar Mar 21 '25 04:03 aredspyinthebase