header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

get-storagegroupcopystatus and email results
Last Post 26 Jun 2008 02:32 PM by khiko. 7 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
khikoUser is Offline
New Member
New Member
Posts:12

--
25 Jun 2008 01:10 AM  

Hi

how do i get the storagegroupcopystatus of two servers and email the results? i do know that using EMS i can get the status of the two servers and output them on the screen by simply doing:

get-storagegroupcopystatus -identity "EXCH\SG1" -StandbyMachine EXCH2

get-storagegroupcopystatus -identity "EXCH2\SG1 -standbyMachine EXCH

and save them as .ps1

how do i make the output to a file for both of the commands and send the output via email?

i know its probably an easy solution but i am new with this things.

thanks

khiko

halr9000User is Offline
Basic Member
Basic Member
Posts:316

--
25 Jun 2008 02:05 PM  

You are right, it's not hard at all. Just pipe your command to set-content and provide a filename. This applies to any object (which can be represented as a string) with PowerShell, not just storage group stuff. e.g.:

get-storagegroupcopystatus -identity "EXCH2\SG1 -standbyMachine EXCH | set-content filename.txt

One thing to watch out for with set-content is the default text encoding is Unicode (double-byte) so the text file is double the size. Use "set-content -encoding ascii" to override.

And there's add-content for appending.

Alternately, you can work in memory without writing anything to a file. e.g.:

$a = get-storagegroupcopystatus -identity "EXCH2\SG1 -standbyMachine EXCH
$a += get-storagegroupcopystatus -identity "EXCH\SG1" -StandbyMachine EXCH2
$a | { some commands here to send the email }

I'd help with the mail sending part but I don't actually use Exchange. :) I can point you to a few non-Exchange ways but I'll just let someone else give the answer you need instead.

khikoUser is Offline
New Member
New Member
Posts:12

--
26 Jun 2008 03:07 AM  
thanks for your reply

get-storagegroupcopystatus -identity "EXCH2\SG1 -standbyMachine EXCH | set-content filename.txt

game me this output...

Microsoft.Exchange.Management.SystemConfigurationTasks.StorageGroupCopyStatusEntry

get-storagegroupcopystatus -identity "EXCH2\SG1 -standbyMachine EXCH | Out-file filename.txt
get-storagegroupcopystatus -identity "EXCH\SG1 -standbyMachine EXCH2 | Out-file filename.txt -append

gave me the output i wanted, problem is how do select the output i want? say if i only want the "Name" of the server, "SummaryCopyStatus" and "LastLogCopied"

cheers
khikoUser is Offline
New Member
New Member
Posts:12

--
26 Jun 2008 03:53 AM  

got what i want i think...


$FromAddress = "senderemail"
$ToAddress = "recipientemail"
$MessageSubject = "messagesubject"
$MessageBody = "messagebody"
$SendingServer = "smtpserver"

get-storagegroupcopystatus -identity "EXCH1\SG1" -StandbyMachine EXCH2 | Select Identity,SummaryCopyStatus,LastInspectedLogTime | Out-File filename.txt
get-storagegroupcopystatus -identity "EXCH2\First Storage Group" -StandbyMachine EXCH1 |Select Identity,SummaryCopyStatus,LastInspectedLogTime | Out-File filename.txt -append

$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress,
$MessageSubject, $MessageBody
$Attachment = New-Object Net.Mail.Attachment("./filename.txt")
$SMTPMessage.Attachments.Add($Attachment)

$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
$SMTPClient.Send($SMTPMessage)

results is below


Identity                            SummaryCopyStatus LastInspectedLogTime    
--------                            ----------------- --------------------    
EXCH1\SG1                    Healthy                         

Identity                            SummaryCopyStatus LastInspectedLogTime    
--------                            ----------------- --------------------    
EXCH2\SG1                    Healthy                         

thanks for your help. i also got some of it from sendmailboxstatus script which i got from another website i think (credit to them)

i think there are more ways to improve the output...

 

 

khikoUser is Offline
New Member
New Member
Posts:12

--
26 Jun 2008 04:44 AM  
hmm actually instead of sending an attachment, is there way to just put the results in the body of an email?
halr9000User is Offline
Basic Member
Basic Member
Posts:316

--
26 Jun 2008 12:43 PM  

Sure. Leave off the two lines which create an attachment object and assign content to it.

$Attachment = New-Object Net.Mail.Attachment("./filename.txt")
$SMTPMessage.Attachments.Add($Attachment)

And above that in line 4, do something like this:

$MessageBody = get-content ./filename.txt

halr9000User is Offline
Basic Member
Basic Member
Posts:316

--
26 Jun 2008 12:47 PM  
I almost forgot, I found this out by looking at the Net.Mail.SMTPClient docs on MSDN.
khikoUser is Offline
New Member
New Member
Posts:12

--
26 Jun 2008 02:32 PM  

thanks! i will try this tomorrow as i am home right now :)

------

tried it, and it works. but the scripts need to be re ordered in order for the get-content to work as it is looking for the output file.

only thing is the message body doesnt look good. probably need to use tables?

 

 

You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer