0

我需要查询一个 AD OU 并列出所有具有关于其帐户和组成员身份的多个属性的用户。CSV 格式将是:

First Name  Last Name   SamAct         Active    New-UserGroup    Old-UserGroup
BIll        Gates       bill.gates     YES       YES              NO
Steve       Jobs        steve.jobs     NO        No               YES

是,否是“他是否活跃”和“他是否是该组的成员”

我几乎完成了以下代码,除了我无法弄清楚如何正确确定他是否是组成员。

有什么建议吗??

function getADAccountStatus($adUserObj)
{
  if($adUserObj.AccountIsDisabled)
  { return "NO";}
  else { return "YES";}
}
function getNGStatus($adUserObj)
{
   if($_.memberof -contains 'New_Usergroup')
  {return "YES"; }
  else  {return "NO"; }
}

$ReportPath = "c:\scripts\report.csv"
$ou = 'OU=Group,DC=domain,DC=com'

$records = Get-QADUser -SearchRoot $ou | Select LastName,FirstName,SamAccountName,memberof

$records | foreach{

  new-object psobject -Property @{
  $LastName = $_.LastName
  $FirstName = $_.FirstName
  Account = $_.SamAccountName
  Active = getADAccountStatus($_)
  NG = getATCStatus($_)

  }} | Select $LastName,$FirstName,Account,Active,NG | Export-Csv $ReportPath -Force -ErrorAction Stop -NoTypeInformation
4

2 回答 2

0

memberOf属性包含用户辅助组的可分辨名称列表,因此您必须像这样检查:

function getNGStatus($adUserObj) {
  $groupName = 'CN=New_Usergroup,CN=Users,DC=example,DC=com'
  if ($adUserObj.memberOf -contains $groupName) {
    return "YES"
  } else {
    return "NO"
  }
}
于 2013-04-02T11:12:32.077 回答
0

这是我要工作的内容:

function getADAccountStatus($adUserObj)
{
if($adUserObj.AccountIsDisabled)
{
    return "NO";
}
else
{
    return "YES";
}
}

function getNGStatus($adUserObj)
{   
$group = @(($_.MemberOf -split (“,”)  | Select-string -SimpleMatch "CN=") -replace “CN=”,”")
if($group -contains 'New_Usergroup')
{
    return "YES";
}
else
{
    return "NO";
}
}

$ReportPath = "c:\scripts\report.csv"
$ou = 'OU=Group,DC=domain,DC=com'

$records = Get-QADUser -SearchRoot $ou | Select LastName,FirstName,SamAccountName,memberof

$records | foreach{
new-object psobject -Property @{
LastName = $_.LastName
FirstName = $_.FirstName
Account = $_.SamAccountName
Active = getADAccountStatus($_)
NG = getNGStatus
}} | Select LastName,FirstName,Account,Active,NG | Export-Csv $ReportPath -Force -ErrorAction Stop -NoTypeInformation
于 2013-04-02T15:03:11.040 回答