Skip to content

Commit e80fe74

Browse files
jpsnoverlzybkr
authored andcommitted
add a timeout to test-connection (PowerShell#2492)
1 parent a1edf8f commit e80fe74

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

  • src/Microsoft.PowerShell.Commands.Management/commands/management

src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ public class TestConnectionCommand : PSCmdlet
127127
[ValidateRange((int)0, (int)65500)]
128128
public Int32 BufferSize { get; set; } = 32;
129129

130+
/// <summary>
131+
/// The following is the definition of the input parameter "TimeOut".
132+
/// Time-out value in milliseconds. If a response is not received in this time, no response is assumed. The default is 1000 milliseconds.
133+
/// </summary>
134+
[Parameter]
135+
[ValidateRange((int)1, Int32.MaxValue)]
136+
public Int32 TimeOut { get; set; } = 1000;
137+
130138
/// <summary>
131139
/// The following is the definition of the input parameter "ComputerName".
132140
/// Value of the address requested. The form of the value can be either the
@@ -399,6 +407,9 @@ private string QueryString(string[] machinenames, bool escaperequired, bool sele
399407
FilterString.Append(" And ");
400408
FilterString.Append("BufferSize=");
401409
FilterString.Append(BufferSize);
410+
FilterString.Append(" And ");
411+
FilterString.Append("TimeOut=");
412+
FilterString.Append(TimeOut);
402413
FilterString.Append(")");
403414
return FilterString.ToString();
404415
}
@@ -612,6 +623,7 @@ private void ProcessWSManProtocolForTestConnection()
612623

613624
using (CimSession cimSession = RemoteDiscoveryHelper.CreateCimSession(sourceComp, this.Credential, WsmanAuthentication, cancel.Token, this))
614625
{
626+
WriteVerbose(String.Format("WMI query {0} sent to {1}", querystring, sourceComp));
615627
for (int echoRequestCount = 0; echoRequestCount < Count; echoRequestCount++)
616628
{
617629
IEnumerable<CimInstance> mCollection = cimSession.QueryInstances(

0 commit comments

Comments
 (0)