How to view local admins throughout entire doman??

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Adam Bukowski Adam Bukowski 6 months, 1 week ago.

  • Author
    Posts
  • #62022
    Profile photo of David Pharr
    David Pharr
    Participant

    Function Get-LocalGroup {

    [Cmdletbinding()]

    Param(

    [Parameter(ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)]

    [String[]]$Computername = $Env:COMPUTERNAME,

    [parameter()]

    [string[]]$Group

    )

    Begin {

    Function ConvertTo-SID {

    Param([byte[]]$BinarySID)

    (New-Object System.Security.Principal.SecurityIdentifier($BinarySID,0)).Value

    }
    Function Get-LocalGroupMember {

    Param ($Group)

    $group.Invoke('members') | ForEach {

    $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)

    }

    }

    }

    Process {

    ForEach ($Computer in $Computername) {

    Try {

    Write-Verbose "Connecting to $($Computer)"

    $adsi = [ADSI]"WinNT://$Computer"

    If ($PSBoundParameters.ContainsKey('Group')) {

    Write-Verbose "Scanning for groups: $($Group -join ',')"

    $Groups = ForEach ($item in $group) {

    $adsi.Children.Find($Item, 'Group')

    }

    } Else {

    Write-Verbose "Scanning all groups"

    $groups = $adsi.Children | where {$_.SchemaClassName -eq 'group'}

    }

    If ($groups) {

    $groups | ForEach {

    [pscustomobject]@{

    Computername = $Computer

    Name = $_.Name[0]

    Members = ((Get-LocalGroupMember -Group $_)) -join ', '

    SID = (ConvertTo-SID -BinarySID $_.ObjectSID[0])

    }

    }

    } Else {

    Throw "No groups found!"

    }

    } Catch {

    Write-Warning "$($Computer): $_"

    }

    }

    }

    }

    Get-LocalGroup -Computername $env:COMPUTERNAME -Group Administrators, Users -Verbose | Format-List

  • #62137
    Profile photo of Adam Bukowski
    Adam Bukowski
    Participant

    Hi,

    Mayby this can help you 🙂

    invoke-command -comp (Get-ADComputer -Filter *).dnshostname -ScriptBlock {Get-LocalGroupMember administrators}


    Adam

You must be logged in to reply to this topic.