Solved

PowerShell

Posted on 2014-09-16
8
146 Views
Last Modified: 2014-09-16
The following script works fine. However, if I add the following, it returns expected result. Any idea ? How can I add a heading in front of the message ? Tks

unexpected result
--------------------------
$Body = "Location:" + $Body + "`n" + $Body1

Location            
@{Name=backup_2014_09_15_230003_8368484.bak; LastWriteTime=09/15/2014 23:00:14}

Original Result
---------------------
Name                                                                                LastWriteTime                                              
----                                                                                     -------------                                              
backup_2014_09_02_230001_6570526.bak              2/9/2014 23:00:10                                          
backup_2014_09_03_230001_4905028.bak              3/9/2014 23:00:10      



Original Script
--------------------
$Body = Get-ChildItem \\nas\Backup\HR2 -Recurse |
   Select Name,LastWriteTime | sort-object -property LastWriteTime


$Body1 = Get-ChildItem \\nas\Backup\HR2E -Recurse |
   Select Name,LastWriteTime | sort-object -property LastWriteTime

$Body = $Body + "`n" + $Body1

$Date = Get-date -format "dd/MM/yy HH:mm:ss"

Send-MailMessage `
      -Body ($Body | Out-String) `
      -Subject "Backup Folder - $Date" `
      -From db01@abc.com  `
      -To it@abc.com `
      -SmtpServer exdag.abc.com
0
Comment
Question by:AXISHK
  • 4
  • 4
8 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 40324886
I guess, you are converting the $Body to HTML before sending email. If so, try with..
$Body = @()

$Body += Get-ChildItem \\nas\Backup\HR2 -Recurse | 
    Select Name,LastWriteTime | sort-object -property LastWriteTime


 $Body += Get-ChildItem \\nas\Backup\HR2E -Recurse | 
    Select Name,LastWriteTime | sort-object -property LastWriteTime

Open in new window

0
 

Author Comment

by:AXISHK
ID: 40324896
What's the purpose of  $Body = @() ?

Do you mean the default format for $Body is a HTML text format ?
0
 

Author Comment

by:AXISHK
ID: 40324901
One more check, the heading appear only once instead showing under each file lists. How does it appear like this ?


Name                                                        LastWriteTime                                              
----                                                        -------------
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40324970
$Body = @() - Means setting $Body as a array object..

Do you mean the default format for $Body is a HTML text format ?
If you didn't use the ConvertTo-HTML as I mentioned in your last question, then the email will be sent as plain text and format may not look good.
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 40

Expert Comment

by:Subsun
ID: 40324974
To list the folder information separate, you can use following option..
$Body = @()

$Body += Get-ChildItem \\nas\Backup\HR2 -Recurse | 
    Select Name,LastWriteTime | sort-object -property LastWriteTime |
		ConvertTo-HTML -Property Name,FullName,LastWriteTime -head $a -body "<H3>HR2 Folder Information</H3>"


 $Body += Get-ChildItem \\nas\Backup\HR2E -Recurse | 
    Select Name,LastWriteTime | sort-object -property LastWriteTime |
		ConvertTo-HTML -Property Name,FullName,LastWriteTime -head $a -body "<H3>HR2E Folder Information</H3>"

Open in new window


Also replace -Body ($Body | Out-String) ` with -BodyAsHtml ($Body | Out-String) `
0
 

Author Comment

by:AXISHK
ID: 40325007
Can the heading be left justified ?
Display.png
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 40325035
You can use the following head..
$a = "<style>"
$a = $a + "BODY{background-color:White;}"
$a = $a + "TABLE{border-width: 2px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{text-align:left;border-width: 2px;padding: 0px;border-style: solid;border-color: black;}"
$a = $a + "TD{border-width: 2px;padding: 0px;border-style: solid;border-color: black;}"
$a = $a + "</style>"

Open in new window

0
 

Author Closing Comment

by:AXISHK
ID: 40327188
Tks
0

Featured Post

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Microsoft Azure Powershell Message 5 19
powershell - detection of system errors 3 37
Powershell console output Parsing 5 31
PowerShell select-object returns empty lines 3 17
Utilizing an array to gracefully append to a list of EmailAddresses
Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now