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: File Copy Script using EmCopy & VSS (Legacy)

The script below is for informational purposes. Here is a better version <#.Description FileCopyScript_v1.1.8.ps1 Note: this…

How To Install VMM Agent (SCVMM) Manually

The following snippet assumes that a New Hyper-V Server has been added to the cluster;…

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…