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