Compare commits

..

No commits in common. "6db794ce28d03f37523a2dead8a6f7034dfd4a3c" and "db3914286f562a3936e6c27e907ecdcb96ce2a3d" have entirely different histories.

2 changed files with 6 additions and 9 deletions

1
.gitignore vendored
View File

@ -1 +0,0 @@
.vscode

View File

@ -2,22 +2,20 @@
# Disable-InactiveAdUser
#
$UsersOU = "OU=Users,OU=Default-First-Site-Name,DC=CONTOSO,DC=COM"
$MaxAccountAge = 45
# Allow a grace period for newly created accounts which have not yet logged in
$MinAccountAge = 7
$UsersOU = "OU=Users - Synced,OU=_Quantum Leap,DC=QLCOM,DC=COM"
$SmtpServer = 'contoso-com.mail.protection.outlook.com'
$SmtpServer = 'qlmi-com.mail.protection.outlook.com'
$SmtpPort = 25
$SmtpFrom = 'Contoso SOC <security@contoso.com>'
$SmtpFrom = 'Quantum Leap Security <security@qlmi.com>'
$SmtpTo = @(
'security@contoso.com'
'security@qlmi.com'
)
$SmtpSubject = "Contoso, Inc.: Disabled inactive AD accounts over $MaxAccountAge days"
$SmtpSubject = "Disabled inactive AD accounts over max age $MaxAccountAge days"
# Get a list of enabled AD users who have not logged in in $MaxAccountAge days
$Users = Get-ADUser -SearchBase "$UsersOU" -Filter * -Properties * `
| where { $_.Enabled -eq $true -and [DateTime]::FromFileTime($_.lastLogon) -lt (Get-Date).AddDays(-$MaxAccountAge) -and $_.whenCreated -lt (Get-Date).AddDays(-$MinAccountAge) } `
| where { $_.Enabled -eq $true -and [DateTime]::FromFileTime($_.lastLogon) -lt (Get-Date).AddDays(-$MaxAccountAge) } `
| select DisplayName,userPrincipalName,lastLogon,distinguishedName | % { $_.lastLogon = [DateTime]::FromFileTime($_.lastLogon); $_ }
# Disable the accounts