2016-08-25 5 views
0

나는 AD 그룹의 값을 가져와 헬프 데스크에 보낼 전자 메일에 넣는 PS 스크립트를 작성했습니다. 내가 겪고있는 문제는 AD 그룹의 값이 배열에 있지만 그 값을 별도의 줄에 표시하는 방법을 알 수 없다는 것입니다. 이것은 출력별도의 줄에있는 전자 메일 본문의 배열 값

$members = @(Get-qADGroupMember adgroup -IncludedProperties "DisplayName,sAMAccountName") 
$smtp = "smtpserver.domain.com" 
$to = "[email protected]" 
$from = "[email protected]" 
$subject = "Accounts Disabled" 
$body = "Helpdesk, `n `n" 
$body += "These users have had their passwords reset and their accounts disabled. There is no action required on the part of IT helpdesk, this is strictly to notify you. These users will probably be calling soon: `n `n" 

$body += For ($i=0; $i -lt $members.Length; $i++) { 
    $members[$i -join "`n"] 
} 

$body += "`n" 
$body += "For any questions regarding this, please contact the Information Security Team `n `n" 
$body += "Thank you `n" 
$body += "Information Security" 

:

헬프 데스크, 이들 사용자가 자신의 암호를 재설정하고 자신의 계정 있었다

아래는 내가 세 testusers과 광고 그룹을 사용하고 코드입니다 . IT 헬프 데스크 측에서는 아무런 조치가 필요 없으며, 이는 사용자에게 반드시 알려주는 것입니다. 이러한 사용자는 아마 곧 호출 될 것이다 :이 관한 질문

도메인 \의 testuser1의 도메인 \ testuser2 도메인 \ testuser3 ,

당신에게

어떻게 정보 보안 감사 정보 보안 팀에 문의하시기 바랍니다 해당 그룹의 사용자를 다음과 같이 자신의 줄에 표시 할 수 있습니까?

도메인 \ testuser1
도메인 \ testuser2
도메인 \ testuser3

답변

0

를 작동 이상 - 당신은있어. PowerShell은 줄을 쓰는 것을 좋아합니다. 이미 배열이 있으니 간단하게 추가 할 수 있습니다.

$body = @("Helpdesk,") 
$body += "These users have had their passwords reset and their accounts disabled. There is no action required on the part of IT helpdesk, this is strictly to notify you. These users will probably be calling soon:" 

$body += $members 

전송하기 전에 문자열로 변환하면됩니다. ` ", 헬프 데스크"`$ 바디 = - 후 쉼표주의 :

Send-MailMessage -Body ($body | Out-String) <OtherParameters> 
당신이 말한대로 내가 노력
+0

는 여전히 어쨌든 – user2600700

+0

$ 바디 타입 강제 배열로해야합니다, 덕분에 같은 줄에 그룹 구성원을 표시합니다 '='. – wOxxOm

+0

@wOxxOm, 감사합니다. –

관련 문제