Compare commits

...

2 Commits

View File

@ -19,7 +19,9 @@ $Users = Get-ADUser -SearchBase "$UsersOU" -Filter * -Properties * `
| select DisplayName,userPrincipalName,lastLogon,distinguishedName | % { $_.lastLogon = [DateTime]::FromFileTime($_.lastLogon); $_ } | select DisplayName,userPrincipalName,lastLogon,distinguishedName | % { $_.lastLogon = [DateTime]::FromFileTime($_.lastLogon); $_ }
# Disable the accounts # Disable the accounts
$Users | Disable-ADAccount foreach ($User in $Users) {
Disable-ADAccount -Identity $User.distinguishedName
}
# Email a report # Email a report
if (($Users.distinguishedName).Count -gt 0) { if (($Users.distinguishedName).Count -gt 0) {
@ -29,7 +31,8 @@ if (($Users.distinguishedName).Count -gt 0) {
<ul> <ul>
$($Users | % { "<li>$($_.DisplayName) &lt;$($_.userPrincipalName)&gt;, not logged in since $($_.lastLogon)</li>" }) $($Users | % { "<li>$($_.DisplayName) &lt;$($_.userPrincipalName)&gt;, not logged in since $($_.lastLogon)</li>" })
</ul><br/> </ul><br/>
<p>This email was sent automatically. Please do not reply.</p> <p>This email was sent automatically. Please do not reply.</p><br/>
<p><pre>$($UsersOU) $(Get-Date)</pre></p>
"@ "@
Send-MailMessage -SmtpServer $SmtpServer -Port $SmtpPort -UseSsl -From $SmtpFrom -To $SmtpTo ` Send-MailMessage -SmtpServer $SmtpServer -Port $SmtpPort -UseSsl -From $SmtpFrom -To $SmtpTo `