Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Get local group members on servers issue with output.

$
0
0
Hello
I'm trying to get are local group members on a server. It's working for the most part except the getting the group members.
I'm gettting the following output for the MemberNames.
ServerLocalGroupMembersNames
server1AdministratorsSystem.Object[]
server1AdministratorsSystem.Object[]
server1AdministratorsSystem.Object[]
server1AdministratorsSystem.Object[]
server1Backup OperatorsSystem.Object[]
Clear-Host$Servers=Get-Contentc:\temp\!_listv2.txt$Groups=Get-WMIObjectwin32_group-filter"LocalAccount='$true'"-computername$Server|selectnameforeach ( $Serverin$Servers ) {$MemberNames=@()
Get-WMIObjectwin32_group-filter"LocalAccount='True'"-computername$Server|ForEach-Object{$localgroup=$_.Name$Group= [ADSI]"WinNT://$Server/$LocalGroup,group"$Members=@($Group.psbase.Invoke("Members"))$Members|ForEach-Object {$MemberNames+=$_.GetType().InvokeMember("Name",'GetProperty',$null,$_,$null)$output=""|Select-ObjectServer,LocalGroup,MembersNames$output.Server=$Server$output.LocalGroup=$localgroup$output.Membersnames=$MemberNamesWrite-Output$output$output|Export-Csvc:\temp\getlocalgrpmembers.csv-NoTypeInformation-Append
            }
            }

}
Thanks in advance !!!

Viewing all articles
Browse latest Browse all 6937

Latest Images

Trending Articles



Latest Images