Compare commits
No commits in common. "6db794ce28d03f37523a2dead8a6f7034dfd4a3c" and "db3914286f562a3936e6c27e907ecdcb96ce2a3d" have entirely different histories.
6db794ce28
...
db3914286f
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +0,0 @@
|
||||
.vscode
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user