(Get-GroupMember).Count doesn't Export Result to a File


hi guys,

i'm trying head around exporting groupname that's fetched csv file it's count member. exported data file contains last record in file.. help..?

$distgroups = get-content -path c:\scripts\groups.csv   foreach ($dg in $distgroups)  {  $count = @(get-adgroupmember -identity $dg).count  $reportobj = new-object psobject   $reportobj | add-member noteproperty -name "group name" -value $dg  $reportobj | add-member noteproperty -name "count" -value $count   $result = write-host ($dg) has $($count) members  $result += $reportobj   }  $result | export-csv -path c:\scripts\groupcount.csv -notypeinformation -encoding utf8 

the groupcount.csv  file contain result of last record in

$distgroups = get-content -path c:\scripts\groups.csv

such as;

"group name","count"
"signature mobile","7"

how can export results has been written write-host csv file.. ?

appreciate help.

regards,

hi hms,

add line head of script:

$result = @()

then fix line:

# wrong $result = write-host ($dg) has $($count) members  # better write-host "($dg) has $($count) members"

then should work designed.

cheers,
fred


there's no place 127.0.0.1



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Edit Group Policy

Hyper-V VM not reaching OS 'Logon' screen

DNS question...