Hello,
I found this script Bob wrote and I need to tweak it alittle.
- I would like to read a list of servers from a text file.
- I would like the server name in the output.
$Computer = get-Content -Path c:\temp\!_listv2.txt # How do I feed servers from a text file.
$Computer = [ADSI]"WinNT://$Computer"
$timestamp = Get-Date -Format yyyy-MM-dd
$outfile = "c:\temp\localgroupmembers.csv"
New-Item -ItemType file -Path $outfile -Force -ErrorAction Stop
$Groups = $Computer.psbase.Children | Where {$_.psbase.schemaClassName -eq "group"}
ForEach ($Group In $Groups)
{
"Group: $($Group.Name)"
$Members = @($Group.psbase.Invoke("Members"))
ForEach ($Member In $Members)
{
$Class = $Member.GetType().InvokeMember("Class", 'GetProperty', $Null, $Member, $Null)
$Name = $Member.GetType().InvokeMember("Name", 'GetProperty', $Null, $Member, $Null)
if ($Name)
{
Write-Verbose "-- Member: $Name ($Class)"
$memberproperties = [ordered]@{
Server = $computer.name; # I would like the server name in the output.
Group = $($Group.Name);
Member = "$Name ($Class)"}
$memberObj = New-Object -TypeName psobject -Property $memberproperties
Export-Csv -Path $outfile -InputObject $MemberObj -Append -NoTypeInformation
}
}
}