From 081dff7250e9fe709f24c7a345d508ba7aa31002 Mon Sep 17 00:00:00 2001 From: Marcel Stangenberger Date: Sun, 18 Jun 2023 11:09:36 +0000 Subject: [PATCH] Add 'usercount.ps' --- usercount.ps | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 usercount.ps diff --git a/usercount.ps b/usercount.ps new file mode 100644 index 0000000..4dcbfc7 --- /dev/null +++ b/usercount.ps @@ -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 \ No newline at end of file