Solved

Powershell script to retrieve value for PhysicalHostNameFullyQualified

Posted on 2013-12-16
6
454 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 68

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 18

Expert Comment

by:Raheman M. Abdul
ID: 39722905
Please ignore this comment.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 68

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
Set OWA language and time zone in Exchange for individuals, all users or per database.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now