Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 484
  • Last Modified:

Powershell script to retrieve value for PhysicalHostNameFullyQualified

I am looking to add to the following script that gathers basic server info and exports to a csv.  I need to add a line that will add the value for registry setting HKLM\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters\PhysicalHostName   How could I get this added to this script so the info gets added to this csv being exported?


Get-Content c:\MyListOfIPs.txt |
  Where-Object { Test-Connection $_ -Count 2 -Quiet } |
  ForEach-Object {
    $IPAddress = $_
    Get-WmiObject Win32_NetworkAdapterConfiguration -Filter 'IPEnabled=TRUE' -Computer $IPAddress |
    Where-Object { $_.IPAddress -contains $IPAddress } |
    Select-Object @{n='IPAddress';e={ $IPAddress }}, MACAddress, DNSHostName, PhysicalHostName
  } | Export-Csv C:\MACAddressReport.csv -NoTypeInformation
0
scriptz
Asked:
scriptz
  • 3
  • 2
1 Solution
 
scriptzAuthor Commented:
I need something similar to query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters\" /v "PhysicalHostNameFullyQualified  that will read the registry on remote servers and tell me what is hosting that server.
0
 
QlemoC++ DeveloperCommented:
This code does not perform any error handling, so the registry key needs to exist at all times:
Get-Content c:\MyListOfIPs.txt |
  Where-Object { Test-Connection $_ -Count 2 -Quiet } |
  ForEach-Object {
    $IPAddress = $_
    $reg = 
    Get-WmiObject Win32_NetworkAdapterConfiguration -Filter 'IPEnabled=TRUE' -Computer $IPAddress |
    Where-Object { $_.IPAddress -contains $IPAddress } |
    Select-Object @{n='IPAddress';e={ $IPAddress }}, MACAddress, DNSHostName, PhysicalHostName,
                  @{n='VMHost'; e={ [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey(
                                     'LocalMachine', [IPAddress] $IPAddress
                                    ).OpenSubKey(
                                      'Software\Microsoft\Virtual Machine\Guest\Parameters'
                                    ).GetValue('PhysicalHostNameFullyQualified') }}
  } | Export-Csv C:\MACAddressReport.csv -NoTypeInformation

Open in new window

0
 
Raheman M. AbdulCommented:
Please ignore this comment.
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
scriptzAuthor Commented:
I ran the following and it stops at the point where it should create the csv. If I hit enter it will create the csv but it is blank.


Get-Content c:\MyListOfIPs.txt |
  Where-Object { Test-Connection $_ -Count 2 -Quiet } |
  ForEach-Object {
    $IPAddress = $_
    $reg =
    Get-WmiObject Win32_NetworkAdapterConfiguration -Filter 'IPEnabled=TRUE' -Computer $IPAddress |
    Where-Object { $_.IPAddress -contains $IPAddress } |
    Select-Object @{n='IPAddress';e={ $IPAddress }}, MACAddress, DNSHostName, PhysicalHostName,
                  @{n='VMHost'; e={ [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey(
                                     'LocalMachine', [IPAddress] $IPAddress
                                    ).OpenSubKey(
                                      'Software\Microsoft\Virtual Machine\Guest\Parameters'
                                    ).GetValue('PhysicalHostNameFullyQualified') }}
  } | Export-Csv C:\MACAddressReport.csv -NoTypeInformation
0
 
QlemoC++ DeveloperCommented:
Please remove my line 5, and try again.
0
 
scriptzAuthor Commented:
Get-Content c:\MyListOfIPs.txt |
  Where-Object { Test-Connection $_ -Count 2 -Quiet } |
  ForEach-Object {
    $IPAddress = $_
     
    Get-WmiObject Win32_NetworkAdapterConfiguration -Filter 'IPEnabled=TRUE' -Computer $IPAddress |
    Where-Object { $_.IPAddress -contains $IPAddress } |
    Select-Object @{n='IPAddress';e={ $IPAddress }}, MACAddress, DNSHostName, PhysicalHostName,
                  @{n='VMHost'; e={ [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey(
                                     'LocalMachine', [IPAddress] $IPAddress
                                    ).OpenSubKey(
                                      'Software\Microsoft\Virtual Machine\Guest\Parameters'
                                    ).GetValue('PhysicalHostNameFullyQualified') }}
  } | Export-Csv C:\MACAddressReport.csv -NoTypeInformation
0

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now