I have a script that looks through an OU and lists all Security Groups, and the total members of each.
Import-Module ActiveDirectory $groups = Get-ADGroup -f * -searchbase 'OU to search here' foreach ($group in $groups) { $groupname=($group.name) $membercount=@(Get-ADGroupMember $groupname).count $strdone = ($group.name),',',$membercount Add-content c:\outputfiles\CountofUsersinEachGroup.txt -value $strdone }
The output should look like:
SecGroup1,13
SecGroup2,1
SecGroup3,11
SecGroup4,4
SecGroup5,5
But instead, it looks like the follwing:
SecGroup1
,
13
SecGroup2
,
1
SecGroup3
,
11
SecGroup4
,
4
I’ve used Add-Content many times in other scripts in the past and this is the first time it is “wrapping” to a new line.
My other scripts that use Add-Content are working fine (I checked today) so I’m not sure why the formatting is “off” on this one script.
If someone could let me know what I missed I’d appreciate it.