如何在活动目录中搜索组名?

时间:2015-07-16 13:59:53

标签: powershell active-directory

您好我想知道我的AD组BIDEV位于我的AD中的位置,如下图所示。

它存在,但它在哪里?

另外,有关如何使用Powershell执行此操作的任何示例?

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:1)

也许这会对你有所帮助,这里有一个链接

http://www.indented.co.uk/2008/12/08/returning-the-ou-for-an-object/

答案 1 :(得分:0)

#------------------------------
# first part search for a user
#------------------------------

Clear-Host 

$SearchFor = "mmartin"

import-module activedirectory 
Write-Host "Searching..." 
$all_users_list=Get-ADUser -filter * -properties SamAccountName,sn,GivenName,mail,EmailAddress,LastLogonDate,Country,DistinguishedName,CanonicalName |  
select-object SamAccountName,sn,GivenName,mail,EmailAddress,LastLogonDate,Country,DistinguishedName,CanonicalName -ErrorAction silentlycontinue 

foreach($u in $all_users_list)
{
    if($u.SamAccountName -like "*$SearchFor*")
    {
    $Output = $u.SamAccountName + " - " + $u.DistinguishedName
    Write-Host $Output 
    }
}

Write-Host "Done" 
#that will work
#just put what you want at the top in "SearchFor"
#mmartin my powershell guru - 16-july-2015


#------------------------------
# second part search for a group
#------------------------------


 Clear-Host 

$SearchFor = "BIDEV"

import-module activedirectory 
Write-Host "Searching..." 
$all_group_list=Get-ADGroup -filter * -properties * |  
select-object * -ErrorAction silentlycontinue 

foreach($u in $all_group_list)
{
    if($u.SamAccountName -like "*$SearchFor*")
    {
    $Output = $u.SamAccountName + " - " + $u.DistinguishedName
    Write-Host $Output 
    }
}

Write-Host "Done" 

enter image description here