none
How to manage AD by using powershell without installing AD module RRS feed

  • Question

  • I want to list all the servers that are connected in a AD from a member server without installing AD module
    Thursday, February 2, 2017 8:49 AM

Answers

  •     

    Dear Sunitha,

          $domain   = "xyz.com"
      $searchDN = "DC=xyz,DC=com "
      $BaseDN   = "LDAP://" + $domain + "/" + $searchDN
    
           $strFilter = "(&(objectCategory=computer))" 
     
            $objDomain = New-Object System.DirectoryServices.DirectoryEntry $BaseDN
            $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
            $objSearcher.SearchRoot = $objDomain
            $objSearcher.SearchScope = "Subtree" 
            $objSearcher.PageSize = 1000 
    
            $objSearcher.Filter = $strFilter
    
             $colResults = $objSearcher.FindAll()
             $colResults

    You can use the above code to get the list of all the computers. Later you can iterate with foreach. It is just a sample

     foreach ($objResult in $colResults)
    
                {$objItem = $objResult.Properties;
                $objItem.name 
    
                
                }

    Mark as answer if it solved your issue

    Regards 

    Naveen


    Naveen Basati


    • Edited by BASATI Thursday, February 2, 2017 11:23 AM modification in code
    • Proposed as answer by FZB Thursday, February 2, 2017 11:25 AM
    • Marked as answer by Sun i ta Friday, February 3, 2017 6:08 AM
    Thursday, February 2, 2017 11:22 AM
  • The solution is very simple:

    ([adsisearcher]'objectclass=computer').FindAll()|%{$_.Properties['name']}


    \_(ツ)_/

    • Proposed as answer by Akabe Thursday, February 2, 2017 6:14 PM
    • Marked as answer by Sun i ta Friday, February 3, 2017 6:08 AM
    Thursday, February 2, 2017 6:08 PM

All replies

  • There are multiple options, easiest one is to use enter-pssession to connect to computer Where ADmodule is installed and then use "get-adcomputer -filter *" command

    or

    you can utilize invoke-command to invoke "Get-adcomputer" to get list of all AD computers

    invoke-command -ComputerName "ServerWhereADmoduleisinstalled"-ScriptBlock {get-adcomputer -filter * }

    • Proposed as answer by SachinWaghmare Thursday, February 2, 2017 9:07 AM
    Thursday, February 2, 2017 9:07 AM
  • thank you.

    But I want to list all AD computers from a member server.

    Regards,

    Sunitha

    Thursday, February 2, 2017 9:25 AM
  •     

    Dear Sunitha,

          $domain   = "xyz.com"
      $searchDN = "DC=xyz,DC=com "
      $BaseDN   = "LDAP://" + $domain + "/" + $searchDN
    
           $strFilter = "(&(objectCategory=computer))" 
     
            $objDomain = New-Object System.DirectoryServices.DirectoryEntry $BaseDN
            $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
            $objSearcher.SearchRoot = $objDomain
            $objSearcher.SearchScope = "Subtree" 
            $objSearcher.PageSize = 1000 
    
            $objSearcher.Filter = $strFilter
    
             $colResults = $objSearcher.FindAll()
             $colResults

    You can use the above code to get the list of all the computers. Later you can iterate with foreach. It is just a sample

     foreach ($objResult in $colResults)
    
                {$objItem = $objResult.Properties;
                $objItem.name 
    
                
                }

    Mark as answer if it solved your issue

    Regards 

    Naveen


    Naveen Basati


    • Edited by BASATI Thursday, February 2, 2017 11:23 AM modification in code
    • Proposed as answer by FZB Thursday, February 2, 2017 11:25 AM
    • Marked as answer by Sun i ta Friday, February 3, 2017 6:08 AM
    Thursday, February 2, 2017 11:22 AM
  • The solution is very simple:

    ([adsisearcher]'objectclass=computer').FindAll()|%{$_.Properties['name']}


    \_(ツ)_/

    • Proposed as answer by Akabe Thursday, February 2, 2017 6:14 PM
    • Marked as answer by Sun i ta Friday, February 3, 2017 6:08 AM
    Thursday, February 2, 2017 6:08 PM
  • Thanks.
    Friday, February 3, 2017 6:10 AM
  • Thanks
    Friday, February 3, 2017 6:12 AM
  •  

    to list all groups in AD, I know it is get-wmiobject  win32_group

    Now, I would like to know commands to list each group members and users.

    Please note that I want "get-wmiobject" commands for this.

    Note: I'm running all these commands from a member server


    • Edited by Sun i ta Friday, February 3, 2017 6:49 AM
    Friday, February 3, 2017 6:47 AM
  • Like this/

    net localgroup users

    net /?


    \_(ツ)_/

    Friday, February 3, 2017 6:50 AM
  • Friday, February 3, 2017 6:56 AM