Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors when trying to expand IPAddress #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Xento
Copy link

@Xento Xento commented Jan 5, 2021

With this fix the following errors disappear:

$dnsAddressList = Resolve-DnsName -Name $fqdn -Server ($dnsServers | Select-Object -First 1) -Type A -DnsOnly | Select-Object -ExpandProperty IPAddress
Select-Object : Die IPAddress-Eigenschaft kann nicht gefunden werden.
In Zeile:1 Zeichen:113

  • ... -First 1) -Type A -DnsOnly | Select-Object -ExpandProperty IPAddress
  •                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (Microsoft.DnsCl...s.DnsRecord_PTR:PSObject) [Select-Object], PSArgumentException
    • FullyQualifiedErrorId : ExpandPropertyNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand

Select-Object : Die IPAddress-Eigenschaft kann nicht gefunden werden.
In Zeile:1 Zeichen:113

  • ... -First 1) -Type A -DnsOnly | Select-Object -ExpandProperty IPAddress
  •                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (Microsoft.DnsCl...s.DnsRecord_PTR:PSObject) [Select-Object], PSArgumentException
    • FullyQualifiedErrorId : ExpandPropertyNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand

This is because of this output:
Resolve-DnsName -Name $fqdn -Server ($dnsServers | Select-Object -First 1) -Type A -DnsOnly

Name Type TTL Section IPAddress


hostname.contoso.de A 1200 Answer 172.30.x.x

Name : contoso.de
QueryType : NS
TTL : 86400
Section : Authority
NameHost : dns.contoso.de

Name : contoso.de
QueryType : NS
TTL : 86400
Section : Authority
NameHost : dns2.contoso.de

dns.contoso.de A 86400 Additional 172.18.x.x
dns2.contoso.de A 3600 Additional 172.17.x.x

With this fix the following errors disappear:

$dnsAddressList = Resolve-DnsName -Name $fqdn -Server ($dnsServers | Select-Object -First 1) -Type A -DnsOnly | Select-Object -ExpandProperty IPAddress
Select-Object : Die IPAddress-Eigenschaft kann nicht gefunden werden.
In Zeile:1 Zeichen:113
+ ...  -First 1) -Type A -DnsOnly | Select-Object -ExpandProperty IPAddress
+                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Microsoft.DnsCl...s.DnsRecord_PTR:PSObject) [Select-Object], PSArgumentException
    + FullyQualifiedErrorId : ExpandPropertyNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand
 
Select-Object : Die IPAddress-Eigenschaft kann nicht gefunden werden.
In Zeile:1 Zeichen:113
+ ...  -First 1) -Type A -DnsOnly | Select-Object -ExpandProperty IPAddress
+                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Microsoft.DnsCl...s.DnsRecord_PTR:PSObject) [Select-Object], PSArgumentException
    + FullyQualifiedErrorId : ExpandPropertyNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand

This is because of this output:
Resolve-DnsName -Name $fqdn -Server ($dnsServers | Select-Object -First 1) -Type A -DnsOnly

Name                                           Type   TTL   Section    IPAddress                                
----                                           ----   ---   -------    ---------                                
hostname.contoso.de                            A      1200  Answer     172.30.x.x                         

Name      : contoso.de
QueryType : NS
TTL       : 86400
Section   : Authority
NameHost  : dns.contoso.de


Name      : contoso.de
QueryType : NS
TTL       : 86400
Section   : Authority
NameHost  : dns2.contoso.de

dns.contoso.de                             A      86400 Additional 172.18.x.x                           
dns2.contoso.de                             A      3600  Additional 172.17.x.x
@@ -928,7 +928,7 @@ Begin {
try {
$ActiveAdapters = (get-netadapter | Where-Object {$_.Status -like "Up"}).Name
$dnsServers = Get-DnsClientServerAddress | Where-Object {$ActiveAdapters -contains $_.InterfaceAlias} | Where-Object {$_.AddressFamily -eq 2} | Select-Object -ExpandProperty ServerAddresses
$dnsAddressList = Resolve-DnsName -Name $fqdn -Server ($dnsServers | Select-Object -First 1) -Type A -DnsOnly | Select-Object -ExpandProperty IPAddress
$dnsAddressList = Resolve-DnsName -Name $fqdn -Server ($dnsServers | Select-Object -First 1) -Type A -DnsOnly | Where-Object -FilterScript {$_.IPAddress} | Select-Object -ExpandProperty IPAddress
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed in #58, it might be better to filter on $FQDN as it addresses additional issues beyond yours as follows:

            $dnsAddressList = Resolve-DnsName -Name $fqdn -Server ($dnsServers | Select-Object -First 1) -Type A -DnsOnly | Where-Object {$_.Name -eq $fqdn} | Select-Object -ExpandProperty IPAddress

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants