Get - vm | Get-vievent email html output

Hello world

I am having trouble pushing results table in an object and then adding the members of the object to an array.  I have had success using the slot method in the past, but I've only tried (previously) with a cmdlet.  In the example below, I'm piping several cmdlets.  Basically, $vms outputs very well, but I can't get any instantiated table to fill later.  The $mainArray will always send as null in the email.  Any ideas?  I really don't want to get vievent in the foreach loop, as it will really slow down the query.

SE connect-viserver test.testdomain.com

$mainArray = @)

$userArray = @)

$timeArray = @)

$msgArray = @)

$CDT = get-Date

$vms = get - VM | Get-VIEvent-Types of information - start $CDT. AddDays(-30)-finishing $CDT | Where {$_.} GetType(). Name - eq "VmBeingDeployedEvent" - or $_. GetType(). Name - eq "VmCreatedEvent" - or $_. GetType(). Name - eq "VmRegisteredEvent"} | Select the username, Createduserid, FullFormattedMessage | Format-Table - AutoSize

foreach ($vm to $vms)

{

$username = $vm. Username

$createdTime = $vm. Createduserid

$msg = $vm. FullFormattedMessage

$userArray += $username

$timeArray += $createdTime

$msgArray += $msg

}

For ($i = 0; $i - lt $userArray.Count; $i ++)

{

$item = new-Object PSObject

$item | Add-Member-type NoteProperty-Name "UserName" - value $userArray [$i]

$item | Add-Member-type NoteProperty - name "time created" - value $timeArray [$i]

$item | Add-Member-type NoteProperty-Name 'Message' - value $msgArray [$i]

$mainArray += $item

}

"$Head = @".

< style >

TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse ;}}

TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black; background-color: #6495ED ;}}

TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black ;}}

< / style >

"@

# #begin send e-mail section.

$comp = get-wmiobject win32_computersystem

$mailFrom = $comp.name

$FromAddr = $mailFrom + "@testdomain.com.

$ToAddr = " " [email protected] "" "

$Subject = "Virtual machines created in the last 30 days"

$SMTPServer = "smtp.testdomain.com".

$Body = $mainArray |  ConvertTo-Html-head $Head | Out-string

Send-MailMessage-to $FromAddr - to $toAddr - subject $Subject - body ($body) - BodyasHtml - SmtpServer $SMTPServer

disconnect-viserver-confirm: $false

Why if complicated, what follows should give the same result.

SE connect-viserver test.testdomain.com

$mainArray = @)

$CDT = get-Date

$mainArray = get - VM | Get-VIEvent-Types of information - start $CDT. AddDays(-3)-finishing $CDT | Where {$_.} GetType(). Name - eq "VmBeingDeployedEvent" - or $_. GetType(). Name - eq "VmCreatedEvent" - or $_. GetType(). Name - eq "VmRegisteredEvent"} |

Select @{N = 'Username'; E={$_. User name}}.

@{N = "time created"; E={$_. Createduserid}},

@{N = 'Message'; E={$_. FullFormattedMessage}}

"$Head = @".

"@

# #begin send e-mail section.

$comp = get-wmiobject win32_computersystem

$mailFrom = $comp.name

$FromAddr = $mailFrom + "@testdomain.com.

$ToAddr = "[email protected]".

$Subject = "Virtual machines created in the last 30 days"

$SMTPServer = "smtp.testdomain.com".

$Body = $mainArray |  ConvertTo-Html-head $Head | Out-string

Send-MailMessage-to $FromAddr - to $toAddr - subject $Subject - body ($body) - BodyasHtml - SmtpServer $SMTPServer

disconnect-viserver-confirm: $false

Tags: VMware

Similar Questions

  • Get-vievent formatted output

    Hello Luke,.

    Instead of the select-object cmdlet, I would use format-table - Autosize. If I do this, I can only direct to cmdlet convertto-html I want. What is the trick here? I need an output formatted due to FullFormattedMessage.

    $fileloc = "c:\error.csv".
    $vievents = get-VIEvent-start (Get-Date). AddHours(-24)-Types 'mistake ' |
    Select-object Createduserid, username, FullFormattedMessage |
    Export-Csv-path $fileloc - NoTypeInformation - UseCulture

    Thank you

    You must use a Format-* cmdlet only as the last cmdlet in a pipeline. The Select-Object cmdlet is used to select only the properties that you want. To better keep this cmdlet. You can convert the output to html format with:

    $a = ""
    
    Get-VIEvent -Start (Get-Date).AddHours(-24) -Types "Error" |
    Select-Object CreatedTime, UserName, FullFormattedMessage |
    ConvertTo-HTML -head $a -body "

    VI Events Information

    " | Out-File VIEvents.htm Start VIEvents.htm

    Best regards, Robert

  • host name of output of get-vievent filter

    Hi guys,.

    I have a question about the host name filtering in an output of get-vievent. for example, I tried to extract only the host name of the following command:

    Get-VIEvent - maxsamples 20000 | where {$_.} GetType(). Name - eq "VmRemovedEvent"} | Sort descending Createduserid | Select FullFormattedMessage

    Already tried some things like split and toppings, but this does not work for me.

    The name of the server is always based on a ground known as SERVER-< description >.

    Sure. For the removed VM also is just an additional line of PowerCLI:

    Get-VIEvent -maxsamples 20000 |
    where {$_.Gettype().Name -eq "VmRemovedEvent"} |
    Sort CreatedTime -Descending |
    Select @{N="VMHost";E={$_.Host.Name}},
      @{N="VM";E={$_.Vm.Name}}
    
  • How can I get my email to stop doing all the updates of mac support?

    How can I get my e-mail to stop receiving all messages from the community of mac support?  My Inbox is implode!

    Follow the instructions here > https://discussions.apple.com/static/apple/tutorial/email.html

  • Can I talk to someone from Adobe in Spain? I get an email or a phone number? a person to ask a few questions, just that.

    Can I talk to someone from Adobe in Spain? I get an email or a phone number? a person to ask a few questions, just that.

    To the link below, click on the still need help? option in the blue box below and choose the option to chat or by phone...
    Make sure that you are logged on the Adobe site, having cookies enabled, clearing your cookie cache.  If it fails to connect, try to use another browser.

    Creative cloud support (all creative cloud customer service problems)
    http://helpx.Adobe.com/x-productkb/global/service-CCM.html ( http://adobe.ly/19llvMN )

  • Export of Get-VIEvent event

    Hello

    I found the get-vievent command output looks like this

    model: false

    key: 8240

    chainId: 8240

    Createduserid: 2009-03-23 14:38:03

    user name:

    Data Center: VimApi.DatacenterEventArgument

    computeResource: VimApi.ComputeResourceEventArgument

    Host: VimApi.HostEventArgument

    VM: VimApi.VmEventArgument

    fullFormattedMessage: Machine virtual viedfs1-clone is connected

    dynamicType:

    dynamicProperty:

    It is possible to get there real name of the host instead of the value VimApi.HostEventArgument?

    What I'm trying to do is to get the list of errors and warnings with time stamp, name the source (host or guest) and completely formatted message. Perfect example is event VC GUI export

    Error 2009-01-30 12:43:20 cannot communicate with a primary agent of HA cluster Cluster1 in Test environment

    error 30/01/2009 12:43:20 abcd.fqdn.com host in Test environment does not

    It is possible to reproduce the logfile that way by VI toolkit?

    Thnx a lot

    The following should do what you want.

    Note that I have export text to a CSV file, which makes it easier to see the different areas

    
    $report = @()
    get-vievent -Types Error,Warning -Start (Get-Date).addminutes(-15) | %{
      $row = "" | Select Time, Text, Host
      $row.Time = $_.CreatedTime.ToString()
      $row.Text = $_.fullFormattedMessage
      if($_.host -ne $null){
         $row.Host = $_.host.name
      }
      else{
        $row.Host = ""
      }
      $report += $row
    }
    $report | Export-Csv "C:\report.csv" -noTypeInformation 
    

    Post edited by: LucD

    Just noticed I put 1500 instead of 15 as an argument to the addminutes method.

  • Get-VIEvent command line options

    Hello list,
    Options of I have a question about the command line for Get-VIevent. I need to get the logs between a given time limit. I'll use this command in a script. If I can make use of Get-Date command output to - Start - Finish settings.
    I have to get the logs between a given time limit. for example I need newspapers between 16:00 to 17:00 on the same day. for that I do use Get-Date command output?
    Thank you
    Ghislain

    Ghislain wrote:

    This way to grep for a particular string. I know there is an option called "findstr". can you please cite the use of this option of findstr?

    There are a few (dozen) different ways to approach this problem in PowerShell. I hope these examples help:

    PS > $a = Get-VIEvent
    PS > $a | group { $_.GetType().BaseType }
    
    Count Name                      Group
    ----- ----                      -----
       20 VimApi.AlarmEvent         {13875, 13874, 13873, 13872, 13853, 13852, 13846, 13845, 13809...
        8 VimApi.SessionEvent       {13871, 13870, 13869, 13823, 13816, 13815, 13813, 13812}
       65 VimApi.VmEvent            {13868, 13867, 13866, 13865, 13864, 13863, 13862, 13861, 13860...
        2 VimApi.HostEvent          {13821, 13819}
        3 VimApi.Event              {13820, 13818, 13784}
        1 VimApi.GeneralEvent       {13817}
        1 VimApi.CustomFieldDefE... {com.icomasoft.PowerScripter.script}
    
    PS > $a | Where-Object { $_.key -eq 13875 }
    
    source               : VimApi.ManagedEntityEventArgument
    entity               : VimApi.ManagedEntityEventArgument
    from                 : gray
    to                   : green
    alarm                : VimApi.AlarmEventArgument
    key                  : 13875
    chainId              : 13845
    createdTime          : 12/7/2008 11:17:27 AM
    userName             :
    datacenter           : VimApi.DatacenterEventArgument
    computeResource      : VimApi.ComputeResourceEventArgument
    host                 : VimApi.HostEventArgument
    vm                   : VimApi.VmEventArgument
    fullFormattedMessage : Alarm Virtual Machine Memory Usage on openfiler changed from Gray to Green
    dynamicType          :
    dynamicProperty      :
    PS > $a | ? { $_.fullFormattedMessage -match "memory" } | select -first 5 | ft key, full* -auto
    
      key fullFormattedMessage
      --- --------------------
    13875 Alarm Virtual Machine Memory Usage on openfiler changed from Gray to Green
    13873 Alarm Virtual Machine Memory Usage on vcenter.halr9000.com changed from Gray to Green
    13853 Alarm Virtual Machine Memory Usage on vcenter.halr9000.com changed from Green to Gray
    13846 Alarm Virtual Machine Memory Usage on openfiler changed from Green to Gray
    13809 Alarm Virtual Machine Memory Usage on openfiler changed from Gray to Green
    

    [PowerShell MVP |] [ https://mvp.support.microsoft.com/profile=5547F213-A069-45F8-B5D1-17E5BD3F362F], the VI Toolkit forum moderator

    Author of the forthcoming book: VMware Infrastructure Management with PowerShell

    Co-host, PowerScripting Podcast (http://powerscripting.net)

    Need help in General, other than VMware PowerShell? Try the PowerShellCommunity.org forums

  • Why do I get an email every time that I use my browser to access iCloud Info?

    whenever I use a browser to access iCloud, I get an email to tell me that this has happened since MY long held MacBookAir why is it happening?

    Whenever your account is accessible by a new method, you are warned that happened, even when you did. If I somehow accessed your account on a browser you will receive the warning.

  • How can I get my emails on my MacPro iCloud?

    How can I get my emails on my MacPro iCloud?

    Launch the email application, select accounts from the mail menu, click the iCloud icon in the list, and then provide the required information.

    If you do not yet have an iCloud account, set up the first (Apple ID and password).

    ----------

    Guide to basics of the Apple Mac:

    https://www.Apple.com/support/macbasics/

  • Just after to see if Eric Root was of Rochester, MN, and PV KS. How can I get rich email list?

    Just after to see if Eric Root was of Rochester, MN, and PV KS. How can I get rich email list?

    This who exactly are you referring to when you say, "How can I get off the copious list email? There is no list email however there are discussions on these forums, you can follow. To unfollow one, simply click a track at the top of the page.

  • I make new the old id must paasward wen apple id I go passward, says your id or passward not at even I have received emails but get no email how to find the solution, I, m stuck wat to do

    I make new the old id must paasward wen apple id I go passward, says your id or passward not at even I have received emails but get no email how to find the solution, I, m stuck wat to do

    Have you tried to reset it in security issues? If you are not able to do so, contact Apple support so a security identifier Apple Advisor can help you. 800-275-2273.

  • How can I get sent emails from the old to the new email address?

    I'm moving and will have a new email address (internet society)

    How can I get my emails FORWARDED from my old to my new e-mail address e-mail address?

    You ask what their transfer of your former e-mail provider options. Once you stop the e-mail with your former provider service, you usually don't have that email address more unless you work something with them.
    Thunderbird is an email client software that runs on your computer. It has nothing to do with staging by email around the Internet. Especially e-mail addresses that no longer exist.

  • Because getting an email that recurs every 5 minutes, we were not able to get the new email, even from block the bad email.

    An email was sent to our account from an iPhone; the e-mail contained two photos. For the next two days, that E-mail reproduces itself in our Inbox (with the same time/date) more than two hundred times... like every 8 minutes. I have blocked using the object, and those still in the Inbox disappeared. (We were constantly moving them to the trash). A computer guru suggested I unlock now, and he has not returned. However, because the e-mail arrived Wednesday morning we have not been able to get new emails. They appear on in Yahoo email, but nothing will come by Thunderbird. (Get new emails seems to be "stuck"). Our Norton account has done many tests, and that did not help. Can someone help us get our email back to normal? Moreover, the same email/photos were sent to two other people of the same phone I, and they had no problem at all with him.

    Menu help > troubleshooting information.

    Please copy to the Clipboard and paste the information into a message here so your settings can be checked.

    Connect to your e-mail account using a browser (webmail ;) and delete the e-mail following undownloaded (in case it is corrupted))

  • I don't get an email from a user known to me. It is not in my blocked list and not in the junk e-mail folder. what technique should I use to solve this problem?

    I have a known user that I have been to send/receive email from him for many years. now, I don't get the emails sent to me. If he is using my gmail account, email is sent to thunderbird, and I see the email with gmail address in my Inbox. His e-mails addressed to my sbcglobal address are not in my Inbox, or in my junk e-mail folder. I did not block lists, but I use Spam Assassin. is there a technique to solve this problem? It is the only email address that I don't get.

    Connect to your sbcglobal email by using your browser and see if they are put in a spam folder before Thunderbird never the chance to see it.

  • I get an email several times and unable to receive any other email in my thunderbird... Please advice what should I do?

    For. example - there is an e-mail from a certain person Juber, which I was doing several times while I am unable to get other emails. I hope you got my point.

    Sign in to your account via webmail and delete the message causing the problems.

Maybe you are looking for

  • Verification code must sign in music from apple

    Hello, I have a problem signing in music apple on my edge course of the Galaxy. It tells me to enter a verification code after my password, but there is no field to enter the code in. Does anyone know a solution to this problem?

  • Satellite L300-215: windows Explorer does not respond after recovery

    Hello I got a blue screen - don't know what error message was and then stop.I realized the recovery process to return to output from the computer in the box, but when I start I only go as far as office and then "windows Explorer is not responding". A

  • Qosmio G40 - freezes and the sound of noisy fan

    My G40 seems to have a few erratic startup problems upward. Sometimes during the starting process that the computer seems to freeze everything and all I can hear is a loud fan noise. I tried this remedy in the option restart but have had no joy. Is t

  • New SSD UEFI boot [U430 touch]

    Hi all My Lenovo U430 touch came with a Samsung 128 GB SSD. As it became a bit on the small side, I decided to replace it with a Samsung EVO 250 GB SSD. My first thought was to clone the old SSD and then resize partitions later. I quickly ran into tr

  • Need some advice on the new computer from HP.

    I bought a new HP computer and it shipped just yesterday and delivery date is Thursday (12th).  I am new to HP computers, my other 2 desktops are Dell and Toshiba laptop of my wife. Laptop is Win 7 and desktop computers are Win XP. The most recent Wi