Powershell Get-ADcomputer group membership output in .CSV table format

Hi everyone,

I am trying to make this code give me an out put in following format:

Column A = Computer Name

Column B = Object1

Column C = Object 2

Column D = Object 3

and so on. (e.g. Computername, object1, object 2, object3… everything in one row but separate columns)

What I’m getting is everything in one cell. Code is below. (Pc012345 is name of the computer)

$name = "pc012345" 
write-output($name + @(Get-ADComputer $name | get-adprincipalgroupmembership | select-object -ExpandProperty samaccountname)) |
out-file "d:\anter-test.csv" -append | format-table



If you like to have a CSV file as the result you should use Export-Csv instead Out-File. It’s made for. :wink: Please read the complete help including the examples to learn hot to use it.