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

Absolutely cannot get hashtable columns to line up in email.

$
0
0

OK. So I have been working on a ps script (v2). Everything seems to work fine. editing and running from PowerGUI.

I have this section of code in a function:

$mismatch_ademail = New-Object PSObject -Property @{
LOGON = $_.sAMAccountName
FULLNAME = $rename_user
LASTNAME = $_.lastname
EMAIL = $userprop.Item("mail")
}

$Global:ADmismatch += $mismatch_ademail

If I do a $Global:ADmismatch the columns display on the screen just fine. When I add the variable to the email body nothing is lined it. The columns are there but but not lined up. Ive tried html and that didnt work either.

Here is what I have for email:

$SmtpServer = "smtp.domain.com"
$From = "TEST SCRIPT<AD_USER_UPDATE_SCRIPT@mhg.com>"
[string[]]$To = "user1@email.com"
$Message = New-Object System.Net.Mail.MailMessage( $From , $To )
$Message.Subject = "AD TEST SCRIPT:"
$SMTPClient = New-Object System.Net.Mail.SmtpClient($SmtpServer)

 
Function sendMail
{
  If (!([string]::IsNullOrEmpty($Global:ADmismatch)))
  {
  $Body2 = $Global:ADmismatch | Format-Table -AutoSize | Out-String
  $Message.IsBodyHTML = $false  (also tried $true)
  $Message.body = $Body2
  $SMTPClient.Send($Message)
}

So i tried changing IsBodyHTML - $True (that makes everything in the body to go away.

I'm just trying to get how it looks on the screen to show up even half way like that in the email body. Right now it looks something like this.

FULLNAME LASTNAME LOGON EMAIL
------- -------  ------- ------
Jim A Bob Bob jbob jbob@email.com

Can someone help?

Thx


Viewing all articles
Browse latest Browse all 21975

Trending Articles



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