The E-mail Message body dynamics PowerShell/PowerCLI with data warehouses

Hello what follows is related to this e-mail, but I'm stuck at the rounding of numbers

The E-mail Message body dynamics PowerShell/PowerCLI

I get an email with the following information:

Datastore HealthCheck vCenter

Available data store space
UsedGB data store                                 Free GB                                 Perc Free
Name1 273.30078125                         274.25                                    99%
name2 273.30078125                         274.25                                    99%
Name3 268.466796875                         274.25                                    99%
name4 273.30078125                         274.25                                    99%

Three things I'm stuck: the value UsedGB, woud have first with only two decimal points instead of having 273.30078125, nice to have 273.30. Secondly I do not receive the right percentage. Third: How can I sort the free Perf in the percentage values lowest for the greater? Thanks for your help

Code:

$msg. Object = "vCenter Datastore health CompanyvCenter.
$array0 = @)
$array1 = @)
$array2 = @)
Start-sleep 1
to connect-VIServer $vcserver
$array0 += get-Datastore. Select-Object - ExpandProperty name
$array1 += get-Datastore. Select-Object - ExpandProperty FreeSpaceGB
$array2 = get-Datastore. Select-Object - ExpandProperty CapacityGB
$UsedSpace = [math]: tour (($array2 [$i]-$array1[$i]), 2)
$PercFree = [math]: Round ((100 * $array1 [$i] / $array2[$i]), 0)
$String0 = ' $PercFree$ %.
$i = 0
$j = 0
# Header
$msg. Body += "< FONT COLOR = black > Datastore HealthCheck CompanyvCenter < / POLICE > < BR > < BR >".
# Datastore header
$msg. Body += "< B > < FONT COLOR = black > Datastore space available < / POLICE > < / b > < BR >".
$msg. Body += "< B > < COLOR of FONT = black > Datastore < / POLICE > < / b > < B > < FONT COLOR = black > UsedGB < / POLICE > < / b > '."
< B > < FONT COLOR = black > free GB < / FONT > < / b > '
"< B > < FONT COLOR = black > free Perc < / POLICE > < /B >.
# Datasores
0. ($array0.) Count-1) | %{
$msg. Body += "< BR > < DO COLOR = Black > ' + $array0 [$_]
$msg. Body += "< / FONT > < FONT COLOR = Black >" + [math]: tour (($array2 [$_]-$array1[$_]), 2)
#$msg. Body += ' < / POLICE > < DO COLOR = Black > ' + $array1 [$_]
$msg. Body += ' < / POLICE > < COLOR of POLICE black = > ' + $array2 [$_] + ' < / POLICE >.
#$msg. Body += "< / FONT > < FONT COLOR = black >" + [math]: tour (($array2 [$_]-$array1[$_]), 2) + "< station >"
$msg. {"Body +=" "< ARE COLOR = Black >" + [math]: round ((100 * $array1 [$i] / $array2 [$i]), 0) + "$Percent" + "< / FONT > < BR >"}
$msg. Attachments.Add ($att1)
$msg. IsBodyHTML = $true
$smtp. Send ($MSG)
$att1. Dispose()
Disconnect-VIServer $vcserver - confirm: $false

#Here configure your paraneters

$SMTPServer = "Exchange".

$MailSubject = 'vCenter Datastore health CompanyvCenter.

$Email = "[email protected]".

function {Set-AlternatingCSSClasses

(param

[string] $HTMLFragment,

[string] $CSSEvenClass,

[string] $CssOddClass

)

[xml] $xml = $HTMLFragment

$table = $xml. SelectSingleNode ('table')

$classname = $CSSOddClass

{foreach ($tr in $table.tr)}

If ($classname - eq $CSSEvenClass) {$classname = $CssOddClass}

else {$classname = $CSSEvenClass}

$class = $xml. CreateAttribute ('class')

$class.value = $classname

$tr.attributes.append ($class) | Out-null

}

$xml.innerxml | out-string

}

Function report-Datastore {}

$output = @)

Get-Datastore. % {

$props = [ordered]@{'Name'=$_. Name;

"UsedSpace' = [math]: Round (($_.)) CapacityGB - $_. (FreeSpaceGB), 2);

"PercFree" = [math]: Round ((100 * ($_.))) FreeSpaceGB / $_. {(CapacityGB)), 0)}

$output += new-Object - TypeName PSCUstomObject-property $props

}

$output

}

"$style = @".

"@

#Connect to Vcenter

SE connect-VIServer $vcserver

# Trnasform the object in the HTML

$html_DS = report-Datastore.

Sort-Object PercFree |

ConvertTo-HTML-Fragment |

Out-string.

Game-AlternatingCSSClasses - CSSEvenClass 'even' - CssOddClass 'odd '.

$html_DS ="

Data warehouses

$html_DS ".

$params = @{'head' ='vCenter Datastore health CompanyvCenter$style ';

««PreContent =»

HealthCheck CompanyvCenter data store

";

"PostContent' = $html_DS}

# Send email

Send-MailMessage-to $Email - subject $MailSubject-BodyAsHtml (ConvertTo-HTML @params) body - SmtpServer $SMTPServer

# Disconnect Vcenter

Disconnect-VIServer $vcserver - confirm: $false

Tags: VMware

Similar Questions

  • The E-mail Message body dynamics PowerShell/PowerCLI

    Hello, do not know if I am in the right place to post my question on PowerShell/PowerCLI

    I have a powershell script that will send an e-mail message to an outlook client.

    The body of the msg will have two things-related values: Snapshots Active in the virtual environment and CD-ROM attached to virtual machines.

    Let's talk when the e-mail reports more than a CDROM attached, how to increase or decrease the msg body according to results from the virtual environment?

    So far, I have this code:

    if (($Snapshots -eq "yes")  -or ($cdroms -eq "yes")) { 
    $array0 = @() 
    $array1 = @() 
    $array2 = @() 
    $array3 = @() 
    start-sleep 1 connect-VIServer $vcserver 
    $array0 += Get-VM | get-snapshot | %{$_.VM.Name} $array1 += Get-VM | get-snapshot | select-object -expandproperty Name 
    $array2 += Get-VM | get-snapshot | select-object -expandproperty Created 
    $array3 =@(Get-VM | where { $_ | Get-CDdrive | where { $_.ConnectionState.Connected -eq "true" } } | Select-object -ExpandProperty Name) 
    $i = 0 
    $j = 0 
    Do { 
    $msg.Body += "<FONT COLOR=black>VMware HealthCheck vCenter2</FONT><BR><BR>"  + ` 
    "<B><FONT COLOR=black>Snapshots Active</FONT></B><BR>" + ` 
    "<B><FONT COLOR=black>VM Name</FONT></B>"+` 
    "<B><FONT COLOR=black>                                      ` Name</FONT></B>"+` "<B><FONT COLOR=black>                                      ` Created</FONT></B><BR>"+` "<FONT COLOR=Red>"+$array0+"</FONT>"+` "<FONT COLOR=Red>                                    "+$array1+"</FONT>"+` "<FONT COLOR=Red>                                    "+$array2+"</FONT><BR><BR>"+` "<B><FONT COLOR=black>CDROMS Connected (Bad Habit)</FONT></B><BR>"+"<B><FONT COLOR=black>VM Name</FONT></B><BR>"+"<FONT COLOR=Red>"+$array3+"</FONT>" 
    $i++ 
    $j++
    } Until (($array0[$i] -eq $null ) -or ($array3[$j] -eq $null))

    The result I get is:

    From: VMware Healtcheck

    Sent: Thursday, June 20, 2013 13:26

    From: me

    Re: VMware health UPIvCenter2

    VCenter2 VMware HealthCheck

    Active snapshots

    Name of the created virtual machine

    VEEAM1 VEEAM1 Test1 Test2 20/06/2013 09:06:09 06/20/2013 09:31:15

    Connected CDROMS (bad habit)

    Name of the virtual machine

    MAILGATE

    And I would like is:

    From: VMware Healtcheck

    Sent: Thursday, June 20, 2013 13:26

    From: me

    Re: VMware health UPIvCenter2

    VCenter2 VMware HealthCheck

    Active snapshots

    Name of the created virtual machine

    VEEAM1 Test1 20/06/2013 09:06:09

    VEEAM1 Test2 20/06/2013 09:31:15

    Connected CDROMS (bad habit)

    Name of the virtual machine

    MAILGATE

    NOTE: I have multiple snapshots or multiple virtual machines with CD-ROM connected. Thanks for your help.

    You see not all snapshots is because the loop stops when the snapshots or the cdroms are done.

    Assume that you have 3 entries for snapshots and 2 for the cdroms, you will get only 2 lines each.

    I would do something like that

    if (($Snapshots -eq "yes") -or ($cdroms -eq "yes")) {   $array0 = @()   $array1 = @()   $array2 = @()   $array3 = @()   start-sleep 1   connect-VIServer $vcserver  $vms = Get-VM  $snaps = $vms | Get-Snapshot  $array0 = $snaps | %{$_.VM.Name}  $array1 = $snaps| select-object -expandproperty Name   $array2 = $snaps | select-object -expandproperty Created   $array3 =@($vms | where { $_ | Get-CDdrive | where { $_.ConnectionState.Connected -eq "true" } } | Select-object -ExpandProperty Name) 
    
    # Header  $msg.Body += "VMware HealthCheck vCenter2

    "# Snapshot header $msg.Body += "Snapshots Active
    " $msg.Body += "VM NameNameCreated"# Snapshots 0..($array0.Count-1) | %{ $msg.Body += "
    " + $array0[$_] $msg.Body += "" + $array1[$_] $msg.Body += "" + $array2[$_] + "

    " }# CDRom header msg.Body += "CDROMS Connected (Bad Habit)
    "# CDRoms $array3 | %{ $msg.Body += "VM Name
    "+"" + $_ + "" }}

    Note that I don't check if spacing HTML and page layout is as you wanted. You may need to add some spacing.

  • I want a newsletter to read directly in the body of the e-mail message

    I did a 4 page layout newsletter on my Macbook Pro, OS X Yosemite. I don't want to be seen as an attachment when someone opens it. I want to read in the body of the email. Anyone know how?

    There is no simple answer to this unique.

    "To begin to realize that e-mails have no notion of the 'pages'... they are just continuous flow of content, so it is unlikely that you can duplicate your ' 4 page newsletter" in an e-mail message. The best you can do is to approach, but it will become really confusing if you have items that cross the spread or are kept on separate pages.

    Second to that, 'style' (i.e. non-text gross) emails use HTML to format, you must convert your document Pages in HTML format. There is no one-click this option. The best you're likely to get is to copy all Pages content and paste it into a new e-mail message (more a few cleaning). Have you tried? how it worked?

    The advantage of this approach is that non e-mail clients will always see a text version of the email.

    The other option is to 'print' each page as a separate image (for example JPEG) and insert 4 JPEG images in the e-mail message. This will ensure your shape/layout layout, even if it is somewhat difficult for users to navigate... and text browsers will not see any content.

    At the end of the day, you're still at the mercy of the messaging client of the recipient, each of which can have different options for the display of rich content.

    So, still today, fill the physical (printed/hard copy) and the digital worlds / email is still a bit of black magic.

  • How can I add session variables for the subject field and the body of the e-mail Message?

    How can I add session variables for the subject field and the body of the e-mail Message? Tried several combinations, but do not seem to correct the syntax.

    This is the code I have. I need to change all the form variables in $msg in session variables. The $to part is supported. What remains are the $subject and $msg fields.

    $à = « à : ». $_SESSION ["toemail"];
    $subject = '$firstname $lastname, your registration details ';
    $from = "from: [email protected]"; "
    $msg = "Dear $title $firstname $lastname\r\n\nThank for the registration for the design of your dream Home.\r\nWe have received this following details details of you-\r\n\nClient-\r\n\nOccupation: $occupation \r\nPhone No.: $phone \r\nE-mail: $email\r\n\nPresent $ location: \r\n location\r\n\nPresent address: \r\n$ address\r\n\n\nFollowing are specified by you - design requirements \r\n\nBasic Features\r\n\nNo." floors: $floors\r\nNo. of bedrooms: bedrooms\r\nNo of $. of bathrooms: $bathrooms\r\nFloor region: $sqft\r\n\nFurther Suggestions: $ Plan\r\n\nSplit one further\r\n\n\nType floor: $splitfloor\r\n-remarks: $splitfloorremarks\r\nOpen floor: $openfloor\r\n-remarks: $openfloorremarks\r\n\n\nList of the rooms to be Included\r\n\nFoyer: $foyer\r\n-remarks: $foyerremarks\r\nDrawing: $drawing\r\n-remarks: $ alive drawingremarks\r\nFormal: $formalliving\r\n-comments : $ alive formallivingremarks\r\nFamily: $familyliving\r\n-remarks: $familylivingremarks\r\nHome Office: $homeoffice\r\n-remarks: $homeofficeremarks\r\nDining: $dining\r\n-remarks: $diningremarks\r\nMaster room: $master\r\n-remarks: $masterremarks\r\nMaster bathroom: $masterbath\r\n-remarks: $masterbathremarks\r\nMaster Dressing: $masterdress\r\n-remarks: $masterdressremarks\r\nBedroom: $bed\r\n-remarks: $bedremarks\r\nBathroom: $bath\r\n-remarks: $bathremarks\r\nDress: $dress\r\n-comments : $dressremarks\r\nStudy: $study\r\n-remarks: $studyremarks\r\nLibrary: $library\r\n-remarks: $libraryremarks\r\nPowder room: $powder\r\n-remarks: $powderremarks\r\nPrayer room: $prayer\r\n-remarks: $prayerremarks\r\nKitchen: $kitchen\r\n-remarks: $kitchenremarks\r\nPantry: $pantry\r\n-remarks: $pantryremarks\r\nUtility/area of work: $utility\r\n-remarks: $utilityremarks\r\nBalcony: $balcony\r\n-remarks: $balconyremarks\r\nStore: $store\r\n-remarks: $storeremarks\r\nLaundry : $laundry\r\n-remarks: $laundryremarks\r\nVeranda: $veranda\r\n-remarks: $verandaremarks\r\nCar porch: $carporch\r\n-remarks: $carporchremarks\r\nGarage: $garage\r\n-remarks: Theater garageremarks\r\nHome $: $theater\r\n-remarks: room of $theaterremarks\r\nMaid: $maid\r\n-remarks: $maidremarks\r\n\nOther general remarks: $general\r\n\nPlease note that the fields have been left blank in your form will be considered undecided details and used in discretion.\r\nIf of the architect , it better to add more later, design requirements please feel free to reply to this email with the details. « ;
    $fla = mail ($to, $subject, $msg, $from);

    Thanks in advance!

    askintrades wrote:

    How can I add session variables for the subject field and the body of the e-mail Message?

    What you want to do? Given the nature of your question, it seems that you probably don't know what a session variable is used. The PHP manual describes the purpose of sessions here: http://docs.php.net/manual/en/intro.session.php.

    I need to change all the form variables in $msg in session variables. The $to part is supported. What remains are the $subject and $msg fields.

    $à = « à : ». $_SESSION ["toemail"];

    Why do you need to change the form variables in session variables? They are already stored in session variables, or they come directly from the form?

    The $to part is not supported. When you pass $to to the mail() function, it should contain only an e-mail address, not a string that begins with "to:

  • F &amp; G Committee &lt; ' F &amp; G Committee' &gt; is not a valid e-mail address because it is not the form user@host. You need to correct before sending the e-mail message.

    Out with the new v.31.1.0, the: 2 September 2014 version of Thunderbird, I can email is no longer a list of recipients, getting the error msg: F & G Committee < ' F & G Committee' > is not a valid e-mail address because it is not the form user@host. You need to correct before sending the e-mail message. In earlier versions, the addresses of individual e-mail in the list (F & G Committee in this case) are automatically placed in as the e-mail is sent. Is there a solution to this problem?

    Read this.
    https://support.Mozilla.org/en-us/questions/1019019

  • How can I change the color used by highlighting the e-mail messages

    How can I change the color highlighting the e-mail messages?

    Hi Hofstra64,

    If you talk about the highlight appears when you select an e-mail message, this is related to the "Highlight color" parameter in your general settings of OS X. More information can be found in the following link:

      

    Highlight color

      

    Choose the color that you want to see when you put in highlight or select items.

    OS X El Capitan: General preferences

    https://support.Apple.com/kb/PH21910

    Thank you for using communities Support from Apple!

  • Why the letter L return when you write the e-mail message?

    Why the letter L to turn upsided down, write my email, but not in the word document

    Model Loptop Acer Aspire 6930

    Leroy

     
    Hi Leroy,
     
    1 does happen on an e-mail program or an email client online?
    2 do whenever you press the L key on the message?
    3. don't you make changes in the e-mail program?
     
    Step 1: We recommend that you check if the problem persists when you type "OSK" L
    a. Click Start, keyboard and click on on-screen keyboard
    b. open the program and type the e-mail message by using the on screen keyboard to check if the problem persists.
     
    Kind regards
    Syed - Microsoft technical support.
    Visit our Microsoft answers feedback Forum and let us know what you think.
  • Is there a unique ID for the e-mail messages in the Inbox

    Hello

    Is there a unique ID for the e-mail messages in the Inbox as a ToDo

    do we read the ID unique to

    String UniqueID = todo.getString (ToDo.UID, ToDo.ATTR_NONE); where todo is a ToDo

    getMessageID?

  • Windows 7 search returns results from Outlook 2013, but links to the message will not open the e-mail message.

    Windows 7 search returns results from Outlook 2013, but links to the message will not open the e-mail message.  Other results such as Excel or Word work.  When you click on the result of the e-mail, the small window at the bottom of the page displays only the title of the email but no information such as the type of file or the date that you would see with other types of file returned.

    Hi Houston,

    Please refer to the article:

    Open the troubleshooter for search and indexing

    http://Windows.Microsoft.com/en-in/Windows7/open-the-search-and-indexing-Troubleshooter

     
    For outlook, try built-in archiving option to facilitate the research for you. Please see the description and functionality of AutoArchive in Outlook from the link below.
    http://support.Microsoft.com/kb/830119
     
    Let us know the result. If the problem is still not resolved, we will be happy to help you further.
  • When I try to send an e-mail with attached pictures, I am told that the photos will not appear in the e-mail message.

    When I try to send an e-mail with pictures, a pop-up window appears when I hit SEND and says that the photos will not appear in the e-mail message.  How can I fix it?

    original title: e-mail problems.

    Hello

    I suggest that ask you your question on the following link.

    http://answers.Microsoft.com/en-us/windowslive

  • Hello! I'm having a problem to open a session on creative cloud. I can log on to the page on the site, but when I try to download a product, the e-mail message that is broadcast, it is an email from my ex-boyfriend, and I just can't change it! So I'm not

    Hello! I'm having a problem to open a session on creative cloud. I can log on to the page on the site, but when I try to download a product, the e-mail message that is broadcast, it is an email from my ex-boyfriend, and I just can't change it! I'm not able to buy a product! Could you help me, please?

    Quit Adobe Creative Cloud app.

    (1) right-click on the icon in the Finder, then select 'Go - To' folder.
    (2) you will get a text box, type in the following command and then press the 'return '. (" Do not miss ~ symbol" "')

    ~/Library

    It will open the folder of the user's library.

    (3) then navigate to Application Support > Adobe > OOBE. Open the OOBE folder and Opm.db bin file.

    Once you had trashed Opm.db file, restart the Adobe Creative Cloud app and check.

  • You contacted me by phone and said that will send you an e-mail with a link to fix my situation. You never sent the e-mail message.

    Adobe contacted me by phone and said they would send an e-mail with a link to fix my situation. They never sent the e-mail message.

    Unfortunately no one here will be able to help provide you with more information.  If you have a case number, then you must specify what it is so that one of the Adobe employees who visit this forum might be able to investigate it.

    If you don't have a file number, if you can provide information explaining your situation, it would be possible to direct you to contact someone at Adobe, who may be able to help.

  • 6.2.16: when you try to update Itunes, I get the following error message: "there is a problem with this package of can I install."  A program required for this install to complete could not be run.  Contact your support team / packages vendo

    6.2.16: when you try to update ITunes on my Windows laptop, I get the following error message: "there is a problem with this Windows Installer package.  A program required for this teaching to complete could not be run.  Contact your supplier of staff or the package of support ".  There is no associated error code.  I've never had a previous issue with ITunes updates.  Thank you, Debbie

    Repair Apple Software Update since the programs & features Panel configuration and then try again.

    For general advice, see troubleshooting problems with iTunes for Windows updates.

    The steps described in the second case are a guide to remove everything related to iTunes and then rebuild what is often a good starting point, unless the symptoms indicate a more specific approach.

    Review the other boxes and other support documents list to the bottom of the page, in case one of them applies.

    The more information box has direct links with the current and recent if you have problems to download, must revert to an older version or want to try the version of iTunes for Windows (64-bit - for older video cards) as a workaround for problems with installation or operation, or compatibility with third-party software.

    Backups of your library and device should be affected by these measures but there are links to backup and recovery advice there.

    TT2

  • How to use powershell to create data warehouses Fibre Channel

    Hello

    Does anyone know how to use powershell to create data warehouses Fibre Channel?

    A text file lists the data warehouse with data store names and sizes (GB) as input:
    DatastoreName1 10
    DatastoreName2 200
    DatastoreName3 10

    Version5 VMFS file system
    Block size of 1 MB

    The script should ignore LUN ID 0 as long as it is not a data store, it's a startup logic unit number.

    The value in $esxname is correct?

    Do you want to see this name when you

    Get-VMHost | Select name

  • How do to know all the tables on peoplesoft (on Oracle 8.1) with data

    I need to know all the tables on peoplesoft (on Oracle 8.1) < strong > with < facilities > data
    and ignore the tables without data.

    It takes to write a pl/sql procedure or is there an easy solution?
    I wrote an example of code, but I am disconnected programming
    for the long and I need help.
    Thanks in advance
    Pls answer
    _______________
    Cursosr curtab is select table_name from dba_tables;
    curtab() loop
    Select count (*) x from curtab;
    If x & gt; 0
    UTL_FILE. Write ('curtab')
    on the other
    null;
    endif;
    end loop;
    ____________________

    Julia wrote:
    I need to know all the tables on peoplesoft (on Oracle 8.1) with data
    > & ignore tables without data.
    >
    > It takes to write a pl/sql procedure or is there an easy solution?
    > I wrote a code example, but I am disconnected programming
    > for a long time and I need help.
    > Thanks in advance
    > Pls answer
    > _______________
    > Cursosr curtab is select table_name from dba_tables;
    > curtab() loop
    > select count (*) x from curtab;
    > If x > 0
    > utl_file.write ('curtab')
    > other
    > null;
    > endif;
    > end of loop;
    > ____________________

    Consider using the user_tables and it works the relevant schema rather than dba_tables breast or of all_tables as these allows you to specify the schema name too will require.

    set serveroutput on;
    
    DECLARE
      cursor curtab is
        select table_name
        from   user_tables;
      --from   all_tables where owner = '';
      v_cnt NUMBER;
    BEGIN
      FOR t IN curtab
      LOOP
        EXECUTE IMMEDIATE 'select count(*) from '||t.table_name INTO v_cnt;
        IF v_cnt > 0 THEN
          DBMS_OUTPUT.PUT_LINE(t.table_name);
        END IF;
      END LOOP;
    END;
    /
    

    Or...

    Ensure that statistics were collected for the schema and examine the value of num_rows in the user_tables view. ;)

Maybe you are looking for