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
Solved

Powershell script to retrieve value for PhysicalHostNameFullyQualified

Posted on 2013-12-16
6
463 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
  • 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 69

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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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 69

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Set OWA language and time zone in Exchange for individuals, all users or per database.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 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