Created
February 2, 2018 12:35
-
-
Save pwnz22/846a9113c8c7b3ebb9ebd06738639966 to your computer and use it in GitHub Desktop.
Send email to AD users
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###Модуль для обращения к AD | |
import-module activedirectory | |
import-module New-SWRandomPassword | |
###Модуль, который при запуске скрипта спрашивает имя пользователя(логин), у которого должен поменяться пароль | |
###$userset = Read-Host "Введите название группы:" | |
$userset = "All-Users" | |
###массив, в котором храняться логины пользователей(меняем SMS на название вашей ГРУППЫ из AD) | |
[array]$u = Get-ADGroupMember $userset | |
###переменная счетчик | |
[int]$a = 0 | |
###измеряем количество пользователей в группе(это нужно чтобы знать длину цикла) | |
[int]$b = $u.Length | |
do { | |
$u[$a] = Get-ADUser $u[$a] -properties PasswordExpired, Enabled, PasswordNeverExpires, Mobile | |
$Account = $u[$a].UserPrincipalName | |
$PasswordExpired = $u[$a].PasswordExpired | |
$PasswordNeverExpires = $u[$a].PasswordNeverExpires | |
$Enabled = $u[$a].Enabled | |
$Mobile = $u[$a].Mobile -replace "[^0-9\+]", "" | |
$dateNow = get-date | |
$logText = "$dateNow $Account $Mobile $result" | |
if (!$PasswordNeverExpires -and $PasswordExpired -and $Enabled) { | |
#Write-Host $result | |
if (!(Test-Path 'C:\ad\log.txt')) { | |
$logText > 'C:\ad\log.txt' | |
} else { | |
$logText >> 'C:\ad\log.txt' | |
} | |
$result = New-SWRandomPassword -PasswordLength 10 | |
$securestring = ConvertTo-securestring $result -asplaintext -force | |
get-aduser $u[$a] | set-adaccountpassword -newpassword $securestring -Reset | |
Set-ADuser $u[$a] -changepasswordatlogon $True | |
###Настройки почты | |
} | |
$a = $a+1 | |
} | |
while ($a -ne $b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment