Using -Server in Get-ADxxx

What’s the difference between:

[pre]Get-ADComputer myServer[/pre]

and

[pre]Get-ADComputer myServer -Server myServer[/pre]

when running the command on [pre]myServer[/pre]?

Run times are quite different:

[pre]

1…10 | % { measure-command { Get-ADComputer myServer } | Select -pr TotalMilliseconds } | FT -Auto

TotalMilliseconds

6.0376
6.7838
5.3302
5.0115
4.4948
5.1408
5.9258
5.5986
5.2073
5.1429

[/pre]

and this:

[pre]

1…10 | % { measure-command { Get-ADComputer myServer -Server myServer } | Select -pr Total
Milliseconds } | FT -AutoSize

TotalMilliseconds

4631.853
63.4815
47.3236
47.3748
48.24
45.2564
68.0297
53.0007
48.8903
53.95

[/pre]

 

I think when server is specified, there is a connection established to the server even if its a local machine.

1.I ran a trace-command on the commands and I think the additional bind to the server parameter is causing the additional processing.

[pre]Trace-Command -Name metadata,parameterbinding,cmdlet -Expression {Get-ADComputer Myserver} -PSHost
Trace-Command -Name metadata,parameterbinding,cmdlet -Expression {Get-ADComputer Myserver-Server Myserver} -PSHost [/pre]
<p style=“text-align: left;”>BIND arg [MyServer] to parameter [Server]
DEBUG: ParameterBinding Information: 0 : COERCE arg to [System.String]
DEBUG: ParameterBinding Information: 0 : Parameter and arg types the same, no coercion is needed.
DEBUG: ParameterBinding Information: 0 : Executing VALIDATION metadata: [System.Management.Automation.ValidateNotNullOrEmptyAttribute]
DEBUG: ParameterBinding Information: 0 : BIND arg [MyServer] to param [Server] SUCCESSFUL
DEBUG: ParameterBinding Information: 0 : BIND POSITIONAL args to DYNAMIC parameters</p>
2. Default Value of Get-AdComputer without specifying the Server parameter:
By using the domain of the computer running Windows PowerShell

  1. I ran your commands on a Domain Controller and got similar results.

TotalMilliseconds

2.2368
2.1106
1.6817
1.6796
3.491
1.6714
1.6854
1.7014
2.0254
1.7036

TotalMilliseconds

14.6934
57.2801
17.63
11.0826
12.0556
11.0424
11.0209
10.7756
11.1762
11.3184

Thanks, I’d forgotten about Trace-Command. I was also testing both commands on a DC so the differences were a surprise.

I thought PowerShell always used Active Directory Web Services to run AD queries so I was surprised at the time differences.