$guestVMName="SOMENAME"

function getHyperVHostname{
param([string]$guestVMName=$env:computername)
$hive = [Microsoft.Win32.RegistryHive]::LocalMachine;
$keyPath = 'SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters';
$value = 'HostName';
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($hive, $guestVMName);
$key = $reg.OpenSubKey($keyPath);
return $key.GetValue($value) ;
}

getHyperVHostname -guestVmName $guestVmName