Expanding group members in Administrators Group

Hi there, I have got a script that will get list of users in Admins group in a system. Can you please share how I can get members of groups in Administrators user group in a system. I am trying to get an out like one mentioned below -

Members in Administrators group -

Tom Tom (AD Users)
Harry Harry (AD Users)
MARKETING (AD Group)
Tim Tim (User in Marketing Group)
Laura Laura (User in Marketing Group)

Here is my sample script

$Output = “C:\Temp\UserInfo.txt”

$Servers = Get-Content -Path “C:\Temp\SystemNames.txt”

foreach ($Servers in $Servers)

{

1. To get Local Administrators group Members

Write-Output " Administrators group Members for the Server mentioned above " |out-file $Output -Append

$localgroup = “Administrators”

$Group= [ADSI]“WinNT://$Servers/$LocalGroup,group”

$members = $Group.psbase.Invoke(“Members”)

$members | ForEach-Object { $.GetType().InvokeMember(“Name”, ‘GetProperty’, $null, $, $null) } | Out-File $Output -Append

}

Hi V

I would use Get-LocalGroupMember with PSRemoting.

$Output = "C:\Temp\UserInfo.txt"

$Servers = Get-Content -Path "C:\Temp\SystemNames.txt"

Invoke-Command -ComputerName $servers -ScriptBlock {

    [pscustomobject]@{
        Server = $env:COMPUTERNAME
        Admins = (Get-LocalGroupMember -Group "Administrators")
    }

} | select server,admins | out-file $output -encoding ASCII

If you don’t have PSRemoting available, you could use WMI/CIM as well. I hope this helps.

Thanks Doug. I see the result, its in a straight line with “…” at the end. I tried to update the last line of the script as mentioned below -

“} | select server, admins | Format-List | out-file $Output -encoding ASCII”

Current Output -

Server : Server1
Admins : {DC\User1, DC\User2, DC\User3, DC\User4…}

Its a output format issue, I understand, if you have any suggestions, please let me know.

If you want all the admins listed you could do

Invoke-Command -ComputerName $servers -ScriptBlock {

    [pscustomobject]@{
        Server = $env:COMPUTERNAME
        Admins = (Get-LocalGroupMember -Group “Administrators”)
    }

} | select server,@{n="admins";e={$_.admins -join ", "}} | out-file $output -encoding ASCII

You may want to export it as a CSV, not sure how you plan to consume it. Take care.

[quote quote=242810]If you want all the admins listed you could do

Invoke-Command -ComputerName $servers -ScriptBlock { [pscustomobject]@{ Server = $env:COMPUTERNAME Admins = (Get-LocalGroupMember -Group “Administrators”) } } | select server,@{n=“admins”;e={$_.admins -join ", "}} | out-file $output -encoding ASCII You may want to export it as a CSV, not sure how you plan to consume it. Take care.

[/quote]
Hi Dough, Thank you for that update, I tried I still get the same output. My apologies for the delayed reply as I was on vacation. I can post the out put tomorrow.