PSScripts/Monitor-NewDomainUsers.ps1

21 lines
604 B
PowerShell
Raw Normal View History

2023-12-18 18:01:44 +00:00
# Monitors if any new active directory users are created
$When = ((Get-Date).AddDays(-1)).Date
$GetUsers = Get-ADUser -Filter { whenCreated -ge $When } -Properties whenCreated
$UserChanges = foreach ($User in $GetUsers) {
[PSCustomObject]@{
Name = $user.name
CreatedOn = $user.whencreated
UPN = $user.userprincipalname
}
}
if (!$GetUsers) {Write-Host "Healthy - No new users found"}
else {
Write-Host "New Users Found"
if (($UserChanges | Measure-Object).Count -ne 1){foreach ($User in $UserChanges) { $User }}
else{$UserChanges[0]}
exit 1
}