Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Add Content formatting is wrapping the text.

$
0
0

Okay I tried some changes suggested by others and came up with the following (99% not my code because a poster explained how to use $props via the example code below)

$groups = Get-ADGroup -f * -searchbase 'My OU Here'
foreach ($group in $groups) {
$members=Get-ADGroupMember $groupname | Get-ADUser -Property *
$props=@{
	GroupName=$group.name
	MemberCount=$members.count
	InactiveCount=@($members|?{$_.lockedout -or $_.Enabled -eq $false}).count
	}
New-Object PsObject -Property $props | Format-Table -AutoSize
}

When I run this, I get only about 1/10th of the group information. The rest (vast majority) throw up errors during the Get-ADGroupmember or Get-ADUser section like the following:

(from the Get-ADGroupmember command) + $members=Get-ADGroupMember $groupname | Get-ADUser <<<< -Property *
+ CategoryInfo : ResourceUnavailable: (CN=john.q.pub…,DC=company,DC=com:ADUser)
[Get-ADUser], ADReferralException

(from the Get-ADUser command) : ResourceUnavailable: (CN=norman.prese…,DC=com,DC=:ADUser)

I’m not sure why the errors appear because when I execute the commands manually, I get good data

$m=Get-ADGroupMember SecurityGroupName  | Get-ADUser -Property *
$m | select Name (will list all 47 members of group)
$i=($m|?{$_.lockedout -or $_.enabled -like 'false'}).count
PS F:\> $i
PS F:\> 27 (this is how many accts in this group are disabled or locked out)
PS F:\> $m.count
PS F:\> 47 (this is how many total accts are in this group)

Viewing all articles
Browse latest Browse all 13067

Trending Articles