Forum Discussion

RaymondJ's avatar
4 years ago

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.

3 Replies

  • Anonymous's avatar
    Anonymous

    Ok, since you want properties on each instance, it looks like what you'd need to do is setup a DataSource using ActiveDiscovery and in the Active discovery script, you'd need to discover the attribute of each instance. Your discovery script would need to output in the following format, one line for each object:

    instance5_id##instance5_name######auto.fooProperty=somevalue
    instance6_id##instance6_name######auto.fooProperty=thisvalue
    

    In this case, two instances would be created, called instance5_name and instance6_name, and each would have its own property.

     

    @Mike Moniz is right, if you want device level properties, PropertySource is the way to go.

  • Alright I moved this over to PropertySource, and for now I am using the Remote Registry method:

    $ComputerName = hostname
    
    # Remote Reqistry
    
    $HyperVHost = ([Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$ComputerName)).OpenSubKey('SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters').GetValue('PhysicalHostName')
    
    Write-Host "auto.lmi.PhysicalHost=$(${HyperVHost})"
    
    Exit 0

     

    This is returning what I would expect. Thanks for the help!