You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Test-Connection shows unwanted output when DNS not resolved on Powershell 7.0.0 #12147
As you can see, we're catching everything in there. Not sure why you'd be getting hostname resolution errors here, unless you're using a different Test-Connection command. There are only two cases you should be getting errors from this cmdlet -- when you provide a $null hostname, or when you provide an IP address that doesn't match the requested switch (i.e., providing an IPv6 address and specifying -IPv4 or vice versa).
Just to be sure, can you grab the output from Get-Command Test-Connection so we can see what it's calling?
We catch the hostname resolution error in the method and call WriteError() -- there's nothing that can be done outside the method call itself other than writing false to output. The issue here is that the error still shows in -Quiet mode, so we'd need to handle that in the method.
-Quiet should do what it says on the tin, in my opinion. 🤷♂
If it's erroring, it's not quiet. A user shouldn't have to ask for quiet twice in one command call. That just leads to frustration, at best. If they want the error, they can simply not use -Quiet.
I think we can incorporate that one... Not sure exactly how, but seems like it should be doable to add some code to make it respect cancellation requests.
Activity
vexx32 commentedon Mar 18, 2020
🤔 This is kinda weird. We shouldn't be surfacing any hostname resolution errors...
This code path handles the hostname resolution:
PowerShell/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
Lines 640 to 733 in 43e0e1a
As you can see, we're catching everything in there. Not sure why you'd be getting hostname resolution errors here, unless you're using a different Test-Connection command. There are only two cases you should be getting errors from this cmdlet -- when you provide a
$nullhostname, or when you provide an IP address that doesn't match the requested switch (i.e., providing an IPv6 address and specifying-IPv4or vice versa).Just to be sure, can you grab the output from
Get-Command Test-Connectionso we can see what it's calling?chvol commentedon Mar 18, 2020
Get-Command Test-Connectionvexx32 commentedon Mar 18, 2020
Can you post the result from
$PSVersionTableas well, please, so we have any necessary OS / other info? Thanks! 😊vexx32 commentedon Mar 18, 2020
Oh, I see it.
PowerShell/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
Lines 680 to 704 in 43e0e1a
We should definitely be just returning false here.
iSazonov commentedon Mar 18, 2020
Issue is here
PowerShell/src/Microsoft.PowerShell.Commands.Management/commands/management/TestConnectionCommand.cs
Lines 575 to 577 in 43e0e1a
vexx32 commentedon Mar 18, 2020
We catch the hostname resolution error in the method and call WriteError() -- there's nothing that can be done outside the method call itself other than writing
falseto output. The issue here is that the error still shows in-Quietmode, so we'd need to handle that in the method.iSazonov commentedon Mar 19, 2020
Quiet parameter can be used in interactive session too. If user don't want to get error SilentlyContinue exists.
vexx32 commentedon Mar 19, 2020
-Quietshould do what it says on the tin, in my opinion. 🤷♂If it's erroring, it's not quiet. A user shouldn't have to ask for quiet twice in one command call. That just leads to frustration, at best. If they want the error, they can simply not use
-Quiet.SeeminglyScience commentedon Mar 19, 2020
Rain Sallow (/u/ta11ow) (@vexx32) btw the get host entry call is part of why the command sometimes doesn't respond to stop processing requests.
vexx32 commentedon Mar 19, 2020
That's a very good point... Is there an async/cancellable method for that one you know of?
EDIT: Nevermind, found one! https://docs.microsoft.com/en-us/dotnet/api/system.net.dns.gethostentryasync?view=netcore-3.1
I think we can incorporate that one... Not sure exactly how, but seems like it should be doable to add some code to make it respect cancellation requests.
SeeminglyScience commentedon Mar 19, 2020
Rain Sallow (/u/ta11ow) (@vexx32) Since there's no cancel, all you can really do is something like: