How can I use Power Shell 2.0 to join a computer to the domain

Tagged: 

This topic contains 4 replies, has 3 voices, and was last updated by  Yong Zhang 4 years, 4 months ago.

  • Author
    Posts
  • #6652

    Yong Zhang
    Participant

    The Parameter -ComputerName of Add-Computer is working only in PowerShell 3.0, right?

    So how can I use PowerShell 2.0 to add a computer to domain remotely? (without using Enter-PSSession)

    Thanks.

  • #6656

    Don Jones
    Keymaster

    Win32_ComputerSystem in WMI, I believe.

  • #6675

    Yong Zhang
    Participant

    Thank you Donl for your response, found a workaround here, but need to Enable-PSsession on target server.

    Invoke-Command -ComputerName server1 -Credential administrator {Add-Computer -DomainName demo -Credential demo\user1}

     

  • #6681

    Richard Siddaway
    Moderator

    Add-Computer will do the job – I think it uses WMI under the covers

    As Don stated the Win32_ComputerSystem class can do the job for you using the JoinDomainOrWorkgroup method

    $class = Get-CimClass Win32_ComputerSystem

    PS> $class.CimClassMethods["JoinDomainOrWorkgroup"].Parameters

    Name                                                CimType Qualifiers —-                                                ——- ———- AccountOU                                            String {ID, In} FJoinOptions                                         UInt32 {BitMap, ID, In} Name                                                 String {ID, In} Password                                             String {ID, In} UserName                                             String {ID, In}

     

  • #6704

    Yong Zhang
    Participant

    Thanks both, will try Win32_ComputerSystem.

You must be logged in to reply to this topic.