【问题标题】:Utilizing CanonicalName oposed to distinguished name使用与专有名称相反的规范名称
【发布时间】:2017-03-15 23:22:50
【问题描述】:

我想使用规范名称而不是专有名称,因为 csv 中的排序更简洁。
我知道我必须将属性值放入,但问题是在哪里。我不知道它是否在 $oulist 或 $users 变量中。这是我的代码。

Import-Module activeDirectory
$output = Read-Host "'Y' for output to file or any key for output in GUI table view" -foreground Cyan
$fqdn = Read-Host "Enter FQDN domain"
$cred = Get-Credential

Write-Host "Contacting $fqdn domain..." -ForegroundColor Yellow

$domain = (get-addomain $fqdn -Credential $cred | select distinguishedName, pdcEmulator, DNSroot, DomainControllersContainer)

Write-Host "Completed. Enumerating OUs.." -ForegroundColor Yellow

$OUlist = @(Get-ADOrganizationalUnit -filter * -Credential $cred -SearchBase $domain.distinguishedName -SearchScope Subtree -Server $domain.DNSroot)
Write-Host "Completed. Counting users..." -ForegroundColor Yellow

$newlist = foreach ($OU in $OUlist)
{
#The array will automatically have a count property, no need for measure
$Users = Get-ADuser -Filter * -Credential $cred -SearchBase $OU.DistinguishedName -SearchScope OneLevel -Server $domain.pdcEmulator
#Again you already have all of the user object before the loop, just            write-progress for the OUlist that you are looping through
write-progress -Activity "Counting users" -Status "Finding users in $OU" -PercentComplete ([array]::indexof($OUlist, $OU)/$OUlist.count * 100)
[pscustomobject]@{
    OU = $OU.DistinguishedName; Count = ($Users.Count)

    }
}
if ($output -eq "Y")
{
    $newlist | Export-CSV .\OUuserCount.csv -NoTypeInformation -Force
    Write-Host "All done!" -ForegroundColor yellow
}
else
{
$newList | Out-GridView
}

【问题讨论】:

    标签: powershell export-to-csv powershell-4.0


    【解决方案1】:

    我想通了。我需要做的就是改变两个值。 我添加了 canonicalname 的属性值

    $OUlist = @(Get-ADOrganizationalUnit -filter * -Credential $cred -properties CanonicalName -SearchBase $domain.distinguishedName -SearchScope Subtree    -Server $domain.DNSroot)
    

    我改变了 OU 的数组值

    [pscustomobject]@{
        OU = $OU.CanonicalName; Count = ($Users.Count)
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多