Listing users in ad group recursively with powershell script without CmdLets

后端 未结 3 1081
终归单人心
终归单人心 2020-12-11 02:19

I\'m trying to list everyone in a security group in an active directory without using CmdLets in PowerShell. The weird thing with my script is that it works if I list the en

3条回答
  •  臣服心动
    2020-12-11 03:12

    This will get all members of the domain Administrators group, including nested members (requires .NET 3.5).

    $Recurse = $true
    
    Add-Type -AssemblyName System.DirectoryServices.AccountManagement
    $ct = [System.DirectoryServices.AccountManagement.ContextType]::Domain
    $group=[System.DirectoryServices.AccountManagement.GroupPrincipal]::FindByIdentity($ct,'Administrators')
    $group.GetMembers($Recurse)
    

提交回复
热议问题