Solved

Powershell script to retrieve value for PhysicalHostNameFullyQualified

Posted on 2013-12-16
6
472 Views
Last Modified: 2013-12-17
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
Comment
Question by:scriptz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 

Author Comment

by:scriptz
ID: 39722574
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
 
LVL 70

Expert Comment

by:Qlemo
ID: 39722870
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
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39722905
Please ignore this comment.
0
Ready to trade in that old firewall?

Whether you need to trade-up to a shiny new Firebox or just ready to upgrade from whatever appliance you're using now, WatchGuard has the right appliance for you! Find your perfect Firebox today with appliance sizing tool!

 

Author Comment

by:scriptz
ID: 39724007
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
 
LVL 70

Accepted Solution

by:
Qlemo earned 500 total points
ID: 39724038
Please remove my line 5, and try again.
0
 

Author Comment

by:scriptz
ID: 39724119
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question