Hi everyone, I don’t understand much about programming, I found on this site a script that I adapted to my needs but the output is not what I want.
In the csv generated you can see:
“SERVER”,“ADMINISTRATORS”,“DESCRIPTION”
“H2OSRVTEST”,“Administrator”,“Development”
“H2OSRVTEST”,“h2oadmin”,“Development”
“H2OSRV1”,“Administrator”,“Production”
“H2OSRV1”,“usertest”,“Production”
“H2OSRV1”,“h2oadmin”,“Production”
“RADIOLOGIA4”,“Administrator”,“Pc di test”
“RADIOLOGIA4”,“user”,“Pc di test”
“RADIOLOGIA4”,“Domain Admins”,“Pc di test”
but I need to put all members of ADMINISTRATOR group in a single line for each Server, can someone help me? I have tried everything
“SERVER”,“ADMINISTRATORS”,“DESCRIPTION”
“H2OSRVTEST”,“Administrator” “h2oadmin”,“Development”
“H2OSRV1”,“Administrator” “usertest” “h2oadmin”,“Development”
“RADIOLOGIA4”,“Administrator” “user”,“Pc di test”
$computers = Get-ADComputer -Filter * -Properties description -SearchBase "OU=server h2o,OU=sanatrix,DC=assa, DC=local" | select description,name $Results = @() Foreach ($Computer in $Computers){ $Name=$Computer.name $description=$Computer.description write-host $Computer.description $members =[ADSI]"WinNT://$Name/Administrators" $members = @($members.psbase.Invoke("Members")) $members | foreach { $LocalAdmins = $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null) # Create a new object for the purpose of exporting as a CSV $pubObject = new-object PSObject $pubObject | add-member -membertype NoteProperty -Name "SERVER" -Value $Name $pubObject | Add-Member -membertype NoteProperty -name "ADMINISTRATORS" -Value $LocalAdmins $pubObject | Add-Member -MemberType NoteProperty -Name "DESCRIPTION" -Value $description $pubObject # Append this iteration of our for loop to our results array. $Results += $pubObject } } $Results | Export-Csv -Path "C:\temp\ServerLocalAdmins.csv" -NoTypeInformation $Results = $Null