It works like a charm with the last edit of Trondh.
Here is the last version of the code. It will therefore gather all members of the local Administrators group (independently of the language used to name it)
Thanks a lot :) !!
#The Third section will query each computer in the ListOfComputers.txt to get the members of the local group Administrators
$Servers=Get-Content ListOfComputers.txt
$output = 'ListOfLocalAdministratorsGroup.csv'
$results = @()
$objSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-544")
$objgroup = $objSID.Translate( [System.Security.Principal.NTAccount])
$objgroupname = ($objgroup.Value).Split("\")[1]
foreach($server in $Servers)
{
$admins = @()
$group =[ADSI]"WinNT://$server/$objgroupname"
$members = @($group.psbase.Invoke("Members"))
$members | foreach {
$obj = new-object psobject -Property @{
Server = $Server
Admin = $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)
}
$admins += $obj
}
$results += $admins
}
$results| Export-csv $Output -NoTypeInformation