Solved

Powershell script to retrieve value for PhysicalHostNameFullyQualified

Posted on 2013-12-16
6
466 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
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…

679 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