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

PowerShell: Microsoft SQL Database Migration

Update 9/25/20: There's another version of this script has has been rewritten form scratch. IMO,…

PowerShell: 1-Liner to Change Computer Name and Join Active Directory

# The 1-liner Add-Computer -DomainName 'somedomain.com' -credential kimconnect.com\domainadmin1 -ComputerName $env:computernname -newname 'NewName' -restart # Quick…

Reset CBT in VMware

# using VMware.VimAutomation.Coreclsif ( (Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) -eq $null ){Add-PsSnapin VMware.VimAutomation.Core}if ( (Get-PSSnapin…