Using -Server in Get-ADxxx

Welcome Forums General PowerShell Q&A Using -Server in Get-ADxxx

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
2 months, 2 weeks ago.

  • Author
    Posts
  • #164190

    Participant
    Topics: 1
    Replies: 1
    Points: -5
    Rank: Member

    What's the difference between:

    Get-ADComputer myServer

    and

    Get-ADComputer myServer -Server myServer

    when running the command on

    myServer

    ?

    Run times are quite different:

    
    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
    
    

    and this:

    
    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
    
    

     

  • #164202

    Senior Moderator
    Topics: 8
    Replies: 1041
    Points: 3,440
    Helping Hand
    Rank: Community Hero

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

  • #164247

    Participant
    Topics: 2
    Replies: 5
    Points: 50
    Rank: Member

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

    Trace-Command -Name metadata,parameterbinding,cmdlet -Expression {Get-ADComputer Myserver} -PSHost
    Trace-Command -Name metadata,parameterbinding,cmdlet -Expression {Get-ADComputer Myserver-Server Myserver} -PSHost 

    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

    2. Default Value of Get-AdComputer without specifying the Server parameter:
    By using the domain of the computer running Windows PowerShell

    3. 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

  • #164533

    Participant
    Topics: 1
    Replies: 1
    Points: -5
    Rank: Member

    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.

You must be logged in to reply to this topic.