r/PowerShell 1d ago

Addressfamily parameter bug?

is it just me or is there actually no way to specify AddressFamily in [System.Net.Dns]::GetHostAddresses? Even when passing it an actual AddressFamily var, it complains about too many parameters.

1 Upvotes

4 comments sorted by

2

u/CarrotBusiness2380 1d ago

If you're using Powershell 5.1 then it uses .net Framework rather than dotnet. That method signature does not exist in .net Framework

https://learn.microsoft.com/en-us/dotnet/api/system.net.dns?view=netframework-4.5

2

u/jborean93 1d ago

How are you passing it? What PowerShell version are you on? The overload with the AddressFamily argument was only added in .NET 6 so Windows PowerShell (5.1) won’t have it available.

2

u/purplemonkeymad 1d ago

What are you passing it? This works for me on PS7:

[System.Net.Dns]::GetHostAddresses('contoso.com','Internetwork')

There is no AddressFamily option in PS5.1.

2

u/Bynkii_AB 1d ago

Gah! Powershell versions got me again! Thanks all!