Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Import-Module ActiveDirectory -ErrorAction SilentlyContinue
- $password = $args.Get(0).ToString()
- $Result = Get-ADUser ((Search-ADAccount -LockedOut).SamAccountName) | Select-Object SamAccountName,Surname,GivenName,DistinguishedName | ConvertTo-Html | Out-String
- $strFileName = "c:\MRC\lockedout.txt"
- $path = "c:\MRC"
- If ($Result) {
- If(!(test-path $path))
- {
- New-Item -ItemType Directory -Force -Path $path
- }
- $username = 'user3091@mysmtp.fr'
- New-Item $strFileName -ItemType file -Force
- $secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
- $mycreds = New-Object System.Management.Automation.PSCredential ($username, $secpasswd)
- Send-MailMessage -Credential $mycreds -To info@monservice.cloud -From user3091@mysmtp.fr -Subject "Comptes AD Locked !" -Body $Result -BodyAsHtml -SmtpServer srv359.mysmtp.fr
- } elseif (Test-Path $strFileName) {
- Remove-Item $strFileName }
Add Comment
Please, Sign In to add comment