Trying to get password has for a login through PowerShell I've trying to get the password hash for a SQL authentication login via powershell.

The code I'm executing is something like this

Invoke-Sqlcmd -Query "SELECT LOGINPROPERTY('$LoginName', 'PASSWORDHASH') as PasswordHash"  -ServerInstance $SourceInstance


This works in that the query executes fine but the output I get is

PasswordHash

{2, 0, 87, 116...}

I'm guessing (probably incorrectly) that this is due to it returning a varbinary, has anyone experienced this and/or fixed it before?

On a side note I'm pretty sure that a script I have which configures tempdb gets similar output.  I'd like to understand not just how to fix it but why it happens too :)

Cheers
Mat
For SQL 2005+

Invoke-Sqlcmd -Query "SELECT sys.fn_varbintohexstr(CONVERT(VARBINARY(MAX), LOGINPROPERTY('$LoginName', 'PASSWORDHASH'))) as PasswordHash"  -ServerInstance $SourceInstance


You can't use this for everything as it has length limitations, but for this purpose it will be fine.