If you use the commandlet Get-SPDatabase
there are several properties of the returned object that can give you the information you need.
$db = (Get-SPDatabase)[0]
$db.Server
Will print out the full server name, and I would assume instance, for that database. Another interesting property would be
$db.DatabaseConnectionString
That will print out something like
Data Source=SP2013;Initial Catalog=SP2013_State_Service_DB;Integrated Security=True;Enlist=False;Pooling=True;Min Pool Size=0;Max Pool Size=100;Connect Timeout=15
Data Source will contain the full server and instance name as well. I'll convert that code for you and add it as an edit.
Here is the code on the link you gave converted to PoSh. I have not wrapped it in a function as I am not sure how you might want to use it...
if ( (Get-PSSnapin -Name microsoft.sharepoint.powershell -ErrorAction SilentlyContinue) -eq $null )
{
Add-PSSnapin microsoft.sharepoint.powershell
}
Start-SPAssignment -Global
$farm = Get-SPFarm
foreach ($server in $farm.Servers)
{
foreach ($svc in $server.ServiceInstances)
{
if($svc -is [Microsoft.SharePoint.Administration.SPDatabaseServiceInstance])
{
$s = [Microsoft.SharePoint.Administration.SPDatabaseServiceInstance]$svc;
if([System.string]::IsNullOrEmpty($s.Instance))
{
$svc.DisplayName
}
else
{
$svc.DispalyName + "\" + $s.Instance
}
}
}
}
Stop-SPAssignment -Global