Extra SPACES in Subject Line of email

I have a daily script that runs and sends an email to users with passwords soon to expire. The issue I have is in the “Subject line” of the email. The subject line includes in the “user name” and comment about expiring in 10 days or less. Between the user name and the comment includes a lot of extra spaces.

 

$LastsetDate = (get-qaduser -includeallproperties $user).passwordlastset

$Newdate = $LastsetDate.AddDays(90)

start-sleep -s 2

$subject = $user + “your password will expire in 10 days or less”

$smtpServer = “smtp.nnnn.com

$msg = new-object Net.Mail.MailMessage

$smtp = new-object Net.Mail.SmtpClient($smtpServer)

$msg.From = “IThelpdesk_NoReply@nnnn.com

$msg.To.add($user)

$msg.Subject = $subject

$msg.Body = $Message

$smtp.Send($msg)

$UserCount ++

 

Hi RJP - Please trim the user name.

[pre]

$subject = $user.ToString().Trim() + " your password will expire in 10 days or less"

[/pre]

 

Hi Kiran - That worked! TY!