Thaidog
asked on
Need help adding content in to an array
The following script is sending out an email for each esx server I have. What I would like to do is send one big email with all the hosts in it... I know it needs to go in an array but I am not certain how to do it.... any ideas?
ForEach ($vmhost in (Get-Datacenter "Operations" | Get-Vmhost | Sort)) {
$deadpaths = Get-ScsiLun -vmhost $vmhost | `
Get-ScsiLunPath | `
where {$_.State -eq "Dead"} | `
Select ScsiLun,State;
$ol = New-Object -comObject Outlook.Application
$mail = $ol.CreateItem(0)
$Mail.Recipients.Add("me@email.com")
$Mail.Subject = "Report"
$Mail.Body = "
$vmhost $deadpaths
"
$Mail.Send()
}
ASKER
Not sure if mine is working lol - I do not have any bad paths right now... mine looks like this:
I changed the -eq to -ne to hopefully get some output but my email just came back:
(I need to use the email style I am now)
$deadpaths = @()
ForEach ($vmhost in (Get-Datacenter "Operations" | Get-Vmhost | Sort)) {
$deadpaths += Get-ScsiLun -vmhost $vmhost | `
Get-ScsiLunPath | `
where {$_.State -ne "Dead"} | `
Select @{n="vmhost";e={$vmhost}}ScsiLun,State
}
$ol = New-Object -comObject Outlook.Application
$mail = $ol.CreateItem(0)
$Mail.Recipients.Add("person@mail.com")
$Mail.Subject = "Report"
$Mail.Body = "
$($Body | ConvertTo-HTML | Out-String)
"
$Mail.Send()
I changed the -eq to -ne to hopefully get some output but my email just came back:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTML TABLE</title>
</head><body>
<table>
</table>
</body></html>
(I need to use the email style I am now)
Do you get result for following code?
$deadpaths = @()
ForEach ($vmhost in (Get-Datacenter "Operations" | Get-Vmhost | Sort)) {
$deadpaths += Get-ScsiLun -vmhost $vmhost | `
Get-ScsiLunPath | `
where {$_.State -ne "Dead"} | `
Select @{n="vmhost";e={$vmhost}}ScsiLun,State
}
$deadpaths
If you get result then try this..
$deadpaths = @()
ForEach ($vmhost in (Get-Datacenter "Operations" | Get-Vmhost | Sort)) {
$deadpaths += Get-ScsiLun -vmhost $vmhost |
Get-ScsiLunPath |
where {$_.State -ne "Dead"} |
Select @{n="vmhost";e={$vmhost}}ScsiLun,State
}
$ol = New-Object -comObject Outlook.Application
$mail = $ol.CreateItem(0)
$Mail.Recipients.Add("person@mail.com")
$Mail.Subject = "Report"
$Mail.HTMLBody = $($deadpaths | ConvertTo-HTML | Out-String)
$Mail.Send()
ASKER
Getting an error:
Select-Object : A positional parameter cannot be found that accepts argument 'S
ystem.Object[]'.
At C:\Users\mcadamtt\SkyDrive\PowerShell\Scripts\get_bad_paths.ps1:15 char:23
+ Select <<<< @{n="vmhost";e={$vmhost}}ScsiLun,State
+ CategoryInfo : InvalidArgument: (:) [Select-Object], ParameterB
indingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
.Commands.SelectObjectCommand
Hmm.. There is a comma (,) missing after @{n="vmhost";e={$vmhost}}
Select @{n="vmhost";e={$vmhost}}, ScsiLun,St ate
Select @{n="vmhost";e={$vmhost}},
ASKER
Ok i corrected that but it now does not return anything in the terminal when I run it....
Are you getting data in email?
ASKER
No...the script just "hangs" like it never gets to the point to send an email.
Hmm... not seeing any issue for script.. Run this code and see if you get the result..
If above code gives you result.. then try this...
$deadpaths = @()
ForEach ($vmhost in (Get-Datacenter "Operations" | Get-Vmhost | Sort))
{
$deadpaths += Get-ScsiLun -vmhost $vmhost |
Get-ScsiLunPath |
where {$_.State -ne "Dead"} |
Select @{n="vmhost";e={$vmhost}}ScsiLun,State
}
$deadpaths
If above code gives you result.. then try this...
$deadpaths = @()
ForEach ($vmhost in (Get-Datacenter "Operations" | Get-Vmhost | Sort))
{
$deadpaths += Get-ScsiLun -vmhost $vmhost |
Get-ScsiLunPath |
where {$_.State -ne "Dead"} |
Select @{n="vmhost";e={$vmhost}}ScsiLun,State
}
$ol = New-Object -comObject Outlook.Application
$mail = $ol.CreateItem(0)
$Mail.Recipients.Add("person@mail.com")
$Mail.Subject = "Report"
$Mail.HTMLBody = $($deadpaths | ConvertTo-HTML | Out-String)
$Mail.Send()
ASKER
Getting an error:
(Edit: Redacted - Modulus_Twelve)
Select-Object : A positional parameter cannot be found that accepts argument 'System.Object[]'.
At line:1 char:171
+ ForEach ($vmhost in (Get-Datacenter "operations" | Get-Vmhost | Sort)) {$deadpaths += Get-ScsiLun -vmhost $vmhost | G
et-ScsiLunPath | where {$_.State -ne "Dead"} | Select <<<< @{n="vmhost";e={$vmhost}}ScsiLun,State}
+ CategoryInfo : InvalidArgument: (:) [Select-Object], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand
(Edit: Redacted - Modulus_Twelve)
ASKER
Never mind.... it's the comma again lol...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok this is working:
ForEach ($vmhost in (Get-Datacenter "Operations" | Get-Vmhost | Sort)) {$deadpaths += Get-ScsiLun -vmhost $vmhost | Get-ScsiLunPath | where {$_.State -ne "Dead"} | Select @{n="vmhost";e={$vmhost}}, ScsiLun,St ate}
And it puts the information in the array just fine... but this is not sending a body:
ForEach ($vmhost in (Get-Datacenter "Operations" | Get-Vmhost | Sort)) {$deadpaths += Get-ScsiLun -vmhost $vmhost | Get-ScsiLunPath | where {$_.State -ne "Dead"} | Select @{n="vmhost";e={$vmhost}},
And it puts the information in the array just fine... but this is not sending a body:
$ol = New-Object -comObject Outlook.Application
$mail = $ol.CreateItem(0)
$Mail.Recipients.Add("name@mail.com")
$Mail.Subject = "Report"
$Mail.Body = "$deadpaths"
$Mail.Send()
Nor is:$ol = New-Object -comObject Outlook.Application
$mail = $ol.CreateItem(0)
$Mail.Recipients.Add("name@mail.com")
$Mail.Subject = "Report"
$Mail.Body = $deadpaths
$Mail.Send()
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Eureka! It works!!!
Great!!.. Don't forget to mark answer..:-)
I am using Send-MailMessage to send email..
Open in new window