Posted On January 6, 2020

PowerShell: Get Hyper-V Host Name from Inside Guest VM

kimconnect 0 comments
blog.KimConnect.com >> Codes , Virtualization >> PowerShell: Get Hyper-V Host Name from Inside Guest VM
$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

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Basic CSS: Give a Background Color to a div Element

<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css"><style>.red-text {color: red;}h2 {font-family: Lobster, monospace;}p {font-size: 16px;font-family: monospace;}.thick-green-border {border-color: green;border-width: 10px;border-style:…

Basic JavaScript: Escaping Literal Quotes in Strings

var myStr = "Yo Mama said, \"have some cookies\"";

Basic CSS: Add Rounded Corners with border-radius

<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css"><style>.red-text {color: red;}h2 {font-family: Lobster, monospace;}p {font-size: 16px;font-family: monospace;}.thick-green-border {border-color: green;border-width: 10px;border-style:…