【发布时间】:2021-03-28 08:43:46
【问题描述】:
我需要从 Active Directory 创建一个报告。我需要提供所有部门的名单和每个部门的人数。 但是脚本没有用。我有 windows server 2019 和 powershell 5.1
Import-Module ActiveDirectory
$Departments = Get-ADUser -Filter * -Property Department | Select-Object -ExpandProperty Department -Unique
Write-Host List of Departments and Number of Users per Department ... -ForegroundColor Green
Write-Host
foreach ($Department in $Departments) {
Write-Host = Users in $Department => (Get-ADuser -Filter * -Property Department | Where-Object {$_.Department -like "$Department"}).count -ForegroundColor yellow
}
Write-Host
Write-Host Total Users in Active Directory : (Get-ADUSer -Filter *).count -BackgroundColor red -ForegroundColor white
Write-Host
$greenCheck = @{
Object = [Char]8730
ForegroundColor = 'Green'
NoNewLine = $true
}
Write-Host "Report on Users and Departments ... " -NoNewline
Start-Sleep -Seconds 1
Write-Host @greenCheck
Write-Host " (Completed)" -ForegroundColor red ```
【问题讨论】:
标签: powershell windows-server-2019