2014-05-15 2 views
0

만료 된 암호를 사용자에게 알리기 위해 스크립트로 작업하고 있지만 중첩 된 그룹에 대한 결과를 얻는 데 문제가 있습니다. 내 스크립트는 Parent-Test의 회원 인 사용자를 필터링합니다. 이 회원으로 직접 가입하지 않은 사용자는 Child01-TestChild02-Test입니다. Child01Child02은 학부모 - 시험의 구성원입니다.Get-ADuser 및 중첩 된 AD 그룹

Get-ADUser을 사용하여이 작업을 수행 할 수 있습니까? 아니면 Get-ADGroupMember과 같은 것을 사용해야합니까?

$smtpServer="mail.company.com" 
$expireindays = 10 
$ADGroup ="CN=Parent-test,OU=Groups,OU=Test,DC=Test1,DC=Test2,DC=Test3,DC=com" 
$OfficeOU ="OU=Test,DC=Test1,DC=Test2,DC=Test3,DC=com" 

#Get Users From AD who are enabled 
Import-Module ActiveDirectory 
$users = get-aduser -filter {memberof -eq $ADGroup} -properties * -searchbase $OfficeOU |where {$_.Enabled -eq "True"} | where { $_.PasswordNeverExpires -eq $false } | where { $_.passwordexpired -eq $false } 

foreach ($user in $users) 
{ 
$Name = (Get-ADUser $user | foreach { $_.GivenName}) 
$emailaddress = $user.emailaddress 
$passwordSetDate = (get-aduser $user -properties * | foreach { $_.PasswordLastSet }) 
$PasswordPol = (Get-AduserResultantPasswordPolicy $user) 
# Check for Fine Grained Password 
if (($PasswordPol) -ne $null) 
{ 
$maxPasswordAge = ($PasswordPol).MaxPasswordAge 
} 

else 
{ 
$maxPasswordAge = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge 
} 


$expireson = $passwordsetdate + $maxPasswordAge 
$today = (get-date) 
$daystoexpire = (New-TimeSpan -Start $today -End $Expireson).Days 
$subject="Your Network/Outlook password will expire in $daystoExpire days" 
$attachment="C:\Util\Outlook Web App Password Change Procedure.pdf" 
$body =" 
Dear $name, 
<p> Your Network/Outlook password will expire in $daystoexpire days.<br> 
Please follow the instructions in the attached guide to change your password. For  assistance, please contact me or send an email to [email protected]<br> 

if ($daystoexpire -lt $expireindays) 
{ 
Send-Mailmessage -smtpServer $smtpServer -from $from -to $emailaddress -subject $subject -body $body -attachments $attachment -bodyasHTML -priority High 

} 

} 
처음 Get-ADGroupMember $ADGroup -Recursive를 사용하여 그룹 구성원 목록을 수집 한 후 전, 그에 대한 사용자를 일치하는 것

답변

0

: 입력에 대한

$pattern = [regex]::Escape($OfficeOU) 

Get-ADGroupMember $ADGroup -Recursive | 
Get-ADUser -Properties * | 
? { $_.Enabled -and $_.PasswordNeverExpires -eq $false -and $_.passwordexpired -eq $false -and $_.DistinguishedName -match $pattern } 
+0

감사합니다, 나는 그것을 통합하려고 볼 수 있습니다 내가 얻는 것. 방금 전체 스크립트를 표시하도록 내 게시물을 업데이트하여 더 나은 그림을 제공 할 수 있습니다. 사용자에게 notfication을 보내기 위해 다른 것들 중 일부를 참조 할 때 초기 Get-ADuser 명령에서 모든 AD 속성을 가져와야합니다. – YEMyslf

+0

그런 다음 스크립트에서했던 것처럼 '-Properties *'로 간단히 변경하십시오. 필자가 두 가지 암호 속성을 입력 한 유일한 이유는 필자의 샘플이 유효한 곳에서 필요하기 때문입니다. :) –

+0

이것이 설명하기에는 너무 많은 경우 자유롭게 말해주세요! PS로 젖은 채로 발을 닦고 있습니다. "Get-ADGroupMember $ ADGroup -Recursive | get-aduser -properties * | 여기서 {$ _. Enabled -eq"True "} | 여기서 {$ _. PasswordNeverExpires -eq $ false} | 여기서 { $ _. passwordexpired -eq $ false} "나머지 코드가 뒤 따른다. 귀하의 모범적 인 모습과 내 방식의 장점/단점은 무엇입니까? 일치 및 패턴 변수를 사용하지 않습니다. – YEMyslf