Jump to content

Recommended Posts

Posted

Hi,

 

All i want it to show the number of computer objects in a group. It will take to long and it wont be accurate to manually count them. The group will not contain users.

 

Does anyone know how to do this please? I cant find much on Google.

 

Thanks

Posted

I'm not a pc (on my phone in Kuala Lumpur airport!)

 

But it's something like this.

 

Ad - find - select computers from.drop down menu - click advanced - then.select member of - group name.

 

It's possible with users for sure but not 100% if you can with pcs

Posted
Try looking from the custom query (or whatever it is called) at the bottom of the computers drop down. Might be able to do it there. I'm stabbing in the dark without access to a pc!!
Posted

Nothing in custom. Will have a look at csvde, its not really what i want. Also with AD manager plus long term it wont be ideal really.

 

Thanks anyway

Posted

This is for users - you might be able to adapt to show computers in a group

 

csvde -f C:\Get-Group\report.csv -r

"(&(objectCategory=person)(objectClass=user)(whenCreated>=20071008000000.0Z))" -l userPrincipalName,sAMAccountName -s saturn.lcbt.co.uk

 

You could also query AD from a PHP page or similar. Have a desktop now just doing a bit of digging.

  • Thanks 1
Posted

PowerShell?

 

if(!(Get-PSSnapin | Where {$_.name -eq "Quest.ActiveRoles.ADManagement"})) { 
   Add-PSSnapin Quest.ActiveRoles.ADManagement -ErrorAction 0 | Out-Null
}

@(Get-QADGroupMember "[color="#FF0000"]Example Group[/color]" -Enabled).count


# or


Get-QADGroup "[color="#FF0000"]Example Group[/color]" -SizeLimit 0 | Select-Object Name,@{n='MemberCount';e={ (Get-QADGroupMember $_ | Measure-Object).Count}}

  • Thanks 1
Posted

Powershell will work but i havn't used that much!

 

With regards to PHP script there is one below which could be modified to suit Link

 

$user = 'bob';
$password = 'zhlob';
$host = 'myldap';
$domain = 'mydomain.ex';
$basedn = 'dc=mydomain,dc=ex';
$group = 'SomeGroup';

$ad = ldap_connect("ldap://{$host}.{$domain}") or die('Could not connect to LDAP server.');
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);
@ldap_bind($ad, "{$user}@{$domain}", $password) or die('Could not bind to AD.');
$userdn = getDN($ad, $user, $basedn);
if (checkGroupEx($ad, $userdn, getDN($ad, $group, $basedn))) {
//if (checkGroup($ad, $userdn, getDN($ad, $group, $basedn))) {
   echo "You're authorized as ".getCN($userdn);
} else {
   echo 'Authorization failed';
}
ldap_unbind($ad);

/*
* This function searchs in LDAP tree ($ad -LDAP link identifier)
* entry specified by samaccountname and returns its DN or epmty
* string on failure.
*/
function getDN($ad, $samaccountname, $basedn) {
   $attributes = array('dn');
   $result = ldap_search($ad, $basedn,
       "(samaccountname={$samaccountname})", $attributes);
   if ($result === FALSE) { return ''; }
   $entries = ldap_get_entries($ad, $result);
   if ($entries['count']>0) { return $entries[0]['dn']; }
   else { return ''; };
}

/*
* This function retrieves and returns CN from given DN
*/
function getCN($dn) {
   preg_match('/[^,]*/', $dn, $matchs, PREG_OFFSET_CAPTURE, 3);
   return $matchs[0][0];
}

/*
* This function checks group membership of the user, searching only
* in specified group (not recursively).
*/
function checkGroup($ad, $userdn, $groupdn) {
   $attributes = array('members');
   $result = ldap_read($ad, $userdn, "(memberof={$groupdn})", $attributes);
   if ($result === FALSE) { return FALSE; };
   $entries = ldap_get_entries($ad, $result);
   return ($entries['count'] > 0);
}

/*
* This function checks group membership of the user, searching
* in specified group and groups which is its members (recursively).
*/
function checkGroupEx($ad, $userdn, $groupdn) {
   $attributes = array('memberof');
   $result = ldap_read($ad, $userdn, '(objectclass=*)', $attributes);
   if ($result === FALSE) { return FALSE; };
   $entries = ldap_get_entries($ad, $result);
   if ($entries['count'] <= 0) { return FALSE; };
   if (empty($entries[0]['memberof'])) { return FALSE; } else {
       for ($i = 0; $i < $entries[0]['memberof']['count']; $i++) {
           if ($entries[0]['memberof'][$i] == $groupdn) { return TRUE; }
           elseif (checkGroupEx($ad, $entries[0]['memberof'][$i], $groupdn)) { return TRUE; };
       };
   };
   return FALSE;
}

?>

  • Thanks 1
Posted
Not a problem - anything else post up and i'll try n help! got 3 hours to kill!

 

What you doing in KUL?

 

PowerShell?

 

if(!(Get-PSSnapin | Where {$_.name -eq "Quest.ActiveRoles.ADManagement"})) { 
   Add-PSSnapin Quest.ActiveRoles.ADManagement -ErrorAction 0 | Out-Null
}

@(Get-QADGroupMember "[color="#FF0000"]Example Group[/color]" -Enabled).count


# or


Get-QADGroup "[color="#FF0000"]Example Group[/color]" -SizeLimit 0 | Select-Object Name,@{n='MemberCount';e={ (Get-QADGroupMember $_ | Measure-Object).Count}}

 

Just to push it a little :) - Do you know how to make it so an input box appears asking for the group name rather than having to edit the script every time i would like to use it?

 

Thanks

Posted (edited)
Do you know how to make it so an input box appears asking for the group name rather than having to edit the script every time

Here's one way of doing it...

 

Get-QADGroup (Read-Host "Enter your group name") -SizeLimit 0 | Select-Object Name,@{n='MemberCount';e={ (Get-QADGroupMember $_ | Measure-Object).Count}}

 

Edit. Also worth mentioning is that if you have lots of groups with a similar names e.g. group1, group2, etc. You can simply enter group* when prompted. :)

Edited by Arthur
  • Thanks 1
Posted

just heading home from Bali via here.

 

you could have a page which submits variables to the script (using a simple form) and then at the top of script have $groupname $=_Request(groupname);

 

then use a simple form with multiple inputs

 

input type=text name=groupname etc

 

T

Posted
Here's one way of doing it...

 

Get-QADGroup (Read-Host "Enter your group name") -SizeLimit 0 | Select-Object Name,@{n='MemberCount';e={ (Get-QADGroupMember $_ | Measure-Object).Count}}

 

Edit. Also worth mentioning is that if you have lots of groups with a similar names e.g. group1, group2, etc. You can simply enter group* when prompted. :)

 

Hi me again :-)

 

Is it supposed to be so slow? It takes ages for it to ask me for the group name and then when i enter the name it sits there from ages then the window disappears. It doesnt tell me the count ha ha

 

This is my code if you can help?

 

Thanks

 

if(!(Get-PSSnapin | Where {$_.name -eq "Quest.ActiveRoles.ADManagement"})) { 
   Add-PSSnapin Quest.ActiveRoles.ADManagement -ErrorAction 0 | Out-Null
}
Get-QADGroup (Read-Host "Enter your group name") -SizeLimit 0 | Select-Object Name,@{n='MemberCount';e={ (Get-QADGroupMember $_ | Measure-Object).Count}}

Posted
Is it supposed to be so slow?

It's really fast when I run it on one of my servers. :confused:

 

It takes ages for it to ask me for the group name and then when I enter the name it sits there from ages then the window disappears.

Do you have the Quest AD cmdlets installed and how are you running the script? Can you try the following, to see if they are any faster?

 

Add-PSSnapin Quest.ActiveRoles.ADManagement
Get-QADGroup (Read-Host "Enter your group name") -SizeLimit 0 | Select-Object Name,@{n='MemberCount';e={ (Get-QADGroupMember $_ | Measure-Object).Count}}
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

 

Add-PSSnapin Quest.ActiveRoles.ADManagement
Get-QADGroup "Your Group" -SizeLimit 0 | Select-Object Name,@{n='MemberCount';e={ (Get-QADGroupMember $_ | Measure-Object).Count}}
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

 

What happens if you run the code you posted through the PowerShell ISE?

Posted

If it is just a one-off query,

 

In Active Directory Users and Computers, Open the AD directory tree, in the left hand frame click on the computer group, in the right hand frame select all members, right mouse button, select properties and it will give you a count in the group....

  • 5 years later...
Posted

Maybe something stupid, but in Active Directory Users and Computers, you can also do this:

Menu --> View --> Customize... --> "Customize View" : MMC : select also "Description bar".

Now, on top of each detail pane, automatically the total number of objects is displayed.

 

Attention: the count includes the total of *all* displayed objects inside the selected OU in the left pane.

So it could also be a mixture of users, groups, computers and sub-OUs.

 

Just for the record...

Posted (edited)

Wow! This is an old thread. :D

 

These days it's much simpler to do what @FN-GM wanted to do...

 

(Get-ADGroupMember "INSERT-GROUP-NAME-HERE" -Recursive | Where { $_.objectClass-eq "computer" }).Count

Edited by Arthur
  • 1 month later...
Posted

If like me you just want to know the number of workstation you have in AD I think it's even easier.

 

In AD, Find > Computers > and enter *

 

And there are all your servers or workstations listed

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...