26 lines
920 B
PostScript
26 lines
920 B
PostScript
$mailto=
|
|
$mailfrom=
|
|
$mailserv=
|
|
|
|
Function ADCOUNT
|
|
{
|
|
Get-ADOrganizationalUnit -filter * -property Description |
|
|
foreach {
|
|
$u=Get-ADUser -filter * -searchbase $_.distinguishedname -ResultPageSize 2000 -resultSetSize 500 -searchscope Onelevel
|
|
$total=($u | measure-object).count
|
|
$Enabled=($u | where {$_.Enabled} | Measure-Object).count
|
|
$Disabled=$total-$Enabled
|
|
New-Object psobject -Property @{
|
|
Name=$_.Name;
|
|
OU=$_.Distinguishedname;
|
|
Description=$_.Description;
|
|
TotalUsers=$Total;
|
|
Enabled=$Enabled;
|
|
Disabled=$Disabled
|
|
}
|
|
}
|
|
}
|
|
ADCOUNT | out-file c:\Windows\Temp\adcount.txt
|
|
$datum = (get-date -uformat "%B %Y")
|
|
send-MailMessage -To "$mailto" -Subject "AD Count output" -Body "Rapport created on "$datum" -SmtpServer "$mailserv" -From "$mailfrom" -Attachment "c:\windows\temp\adcount.txt"
|
|
remove-item c:\windows\temp\adcount.txt |