My code like this.
# Import Module of Active Directory
Import-Module -Name ActiveDirectory
# Email Variables
$smtp = "10.10.10.10"
$to = alan@company.com
$from = "alan@company.com"
$subject = "Enable OCS account"
$ous ='OU=classEmployee,OU=Accounts,OU=Beijing,OU=CN,OU=AP,DC=company,DC=org', 'OU=classEmployee,OU=Accounts,OU=Shanghai,OU=CN,OU=AP,DC=company,DC=org', 'OU=classEmployee,OU=Accounts,OU=Nanjing,OU=CN,OU=AP,DC=company,DC=org', 'OU=classEmployee,OU=Accounts,OU=Shenzhen,OU=CN,OU=AP,DC=companyn,DC=org',
$users = Foreach ($Ou in $OUs) {Get-ADUser -filter * -searchbase $Ou -Properties name,msRTCSIP-PrimaryUserAddress | where-object {($_."msRTCSIP-PrimaryUserAddress" -eq $null)-and ($_.mail -ne $null)} |select -ExpandProperty name
}
if ( $users -ne $null ) {
$body = @"
Hi Sir,
Please help enable OCS account for below user, thanks.
$users
"@
Send-MailMessage -SmtpServer $smtp -To $to -cc $from -From $from -Subject $subject -Body $body
}
exit
and will got email like this:
Hi sir,
Please help enable OCS account for below user, thanks.
Carrie.Zhang Jianzhuang.Song Ivan.Wu Jessica.Zhao
now I want sort the mail into newline like this:
Hi sir,
Please help enable OCS account for below user, thanks.
Carrie.Zhang
Jianzhuang.Song
Ivan.Wu
Jessica.Zhao
How to change the code?