[cmd title="Administrator: Windows PowerShell"]
$reg = Get-ItemProperty "HKLM:SOFTWARE\Microsoft\System Center\2010\Common\Database"
$cs = "Server=$($reg.DatabaseServerName);Database=$($reg.DatabaseName);Trusted_Connection=True;"
$c = New-Object System.Data.SqlClient.SqlConnection $cs
$c.Open()
$cmd = $c.CreateCommand()
$cmd.CommandText = "SELECT COUNT(*) AS Total,
SUM(CASE WHEN Data IS NOT NULL AND UserName IS NOT NULL THEN 1 ELSE 0 END) AS Usable
FROM dbo.CredentialManagerSecureStorage;"
$r = $cmd.ExecuteReader(); $r.Read()
"Total rows : {0}" -f $r['Total']
"Usable rows: {0}" -f $r['Usable']
$c.Close()
[/cmd]



0 comments