Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

How to sort the send-mailmessage body?

$
0
0

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?






Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>