DataSource creation for Physical Host name in Hyper-V/Windows Environment
Hello, Im looking for some guidance in how best to create a Datasource that will provide the Physical Hostname of a Windows VM (will worry about Linux later). I have the following two Powershell queries that will provide the answer of the Physical Hostname:
$ComputerName = hostname
# Remote Registry Method
([Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$ComputerName)).OpenSubKey('SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters').GetValue('PhysicalHostName')
# WMI Method
(([WMIClass]"\\$ComputerName\ROOT\DEFAULT:StdRegProv").GetStringValue(2147483650,'SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters','PhysicalHostName')).sValue
Either method is fine and when ran from PowerShell return the value I’m looking for at least for the Hyper-V host that holds the VM role. Now the issue I am having is when trying to get this to work either using WMI, Groovy or Powershell either it errors or finds no instances.
How I picture this working is that under the device will be a datasource named: Physical Host or HyperV Hostname, within that datasource will be Host and the Raw Data will include Timestamp and the output of the script.
Any assistance would be great.