Add 'usercount.ps'

This commit is contained in:
Marcel Stangenberger 2023-06-18 11:09:36 +00:00
parent 675c20c96a
commit 081dff7250

26
usercount.ps Normal file
View File

@ -0,0 +1,26 @@
$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