[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

List of VM's with Power State IP addresses and

Posted on 2011-10-31
11
Medium Priority
?
592 Views
Last Modified: 2012-08-13
I am working on this script and I cannot figure out why I am not getting the IP or memory in the email.

Can someone help me.

Thanks!!
Add-PSSnapin VMware.VimAutomation.Core

Connect-VIServer "vcenter" -User "xxxxxxx\xxxxx" -Password "xxxxxxxx"


$strOutFile = "C:\temp\list2.htm"


$head = "<style>"
$head = $head + "BODY{background-color:white;}"
$head = $head + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$head = $head + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
$head = $head + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:PaleGoldenrod}"
$head = $head + "</style>"


$smtpServer = "xxxxxxx" 
$strFrom = "rick@xxxxxxx"
$strTo = "rick@xxxxxxxx"
$strSubject = “Power on list - ” + (get-date -DisplayHint date)
$strBody = "Attached is the list of Power On VM"
$strMail = "<H2><u>" + $strSubject + "</u></H2>"


$vms = Get-VM
$myCol = @()
ForEach ($vm in $vms){
           if ($vm.PowerState -eq "PoweredOn") {
            $myObj = "" | select VMName, Powerstate, IPAddress, MemoryMB
            $myObj.VMName = $VM.Name
            $myObj.Powerstate = $VM.PowerState
            $myObj.Memory = $VM.MemoryMB
            $myObj.IPAddress = (Get-VMGuest -VM $VM).IPAddress[0]       
            $myCol += $myObj
    }
        }
$myCol | Sort-Object VM | ConvertTo-HTML -Head $head -Body $strMail | Out-File $strOutFile


$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($strOutFile)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = $strFrom
$msg.To.Add($strTo)
$msg.Subject = $strSubject
$msg.IsBodyHtml = 1
$msg.Body = Get-Content $strOutFile
$msg.Attachments.Add($att)
$msg.Headers.Add("message-id", "<3BD50098E401463AA228377848493927-1>")	

$smtp.Send($msg)

DisConnect-VIServer

Open in new window

0
Comment
Question by:RickEpnet
  • 6
  • 5
11 Comments
 
LVL 6

Expert Comment

by:morpheios
ID: 37060823
Mistake

$vmview = $vm | Get-View
  $myObj.Memory = $vmconfig.MemoryMB

Open in new window

0
 
LVL 6

Expert Comment

by:morpheios
ID: 37060834
For IP try:

$vmguest = $vm | Get-VMGuest
$myObj.IPAddress = $vmguest.IPAddress[0] 

Open in new window

0
 
LVL 6

Expert Comment

by:morpheios
ID: 37060838
Sorry

$vmview = $vm | Get-View
$vmguest = $vm | Get-VMGuest

$myObj.Memory = $vmview.MemoryMB
$myObj.IPAddress = $vmguest.IPAddress[0] 

Open in new window

0
New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

 
LVL 14

Author Comment

by:RickEpnet
ID: 37060839
Where do these go in the script

$vmview = $vm | Get-View


I tried it like this. Funny the IP address works like this but no memory.


ForEach ($vm in $vms){
           if ($vm.PowerState -eq "PoweredOn") {
            $myObj = "" | select VMName, Powerstate, IPAddress, MemoryMB
            $myObj.VMName = $VM.Name
            $myObj.Powerstate = $VM.PowerState
            $vmview = $vm | Get-View
	    $myObj.Memory = $vmconfig.MemoryMB
            $myObj.IPAddress = (Get-VMGuest -VM $VM).IPAddress[0]       
            $myCol += $myOb

Open in new window

0
 
LVL 6

Expert Comment

by:morpheios
ID: 37060860
MemoryMB defined in view not config
0
 
LVL 14

Author Comment

by:RickEpnet
ID: 37060868
Ok I am very new at this how do I get View to work in my script or am I missing something here?
0
 
LVL 6

Expert Comment

by:morpheios
ID: 37060871
$vmview = $vm | Get-View

than replace
$myObj.Memory = $vmconfig.MemoryMB
to
$myObj.Memory = $vmview.MemoryMB
0
 
LVL 14

Author Comment

by:RickEpnet
ID: 37060891
I am sure it is me but that did not work. Here is what I have. And here is what the email looks like.
$vms = Get-VM
$myCol = @()
ForEach ($vm in $vms){
           if ($vm.PowerState -eq "PoweredOn") {
            $myObj = "" | select VMName, Powerstate, IPAddress, MemoryMB
            $myObj.VMName = $VM.Name
            $myObj.Powerstate = $VM.PowerState
	    $vmview = $vm | Get-View
	    $myObj.Memory = $vmview.MemoryMB
            $myObj.IPAddress = (Get-VMGuest -VM $VM).IPAddress[0]       
            $myCol += $myObj
    }
        }

Open in new window

10-31-2011-11-23-49-PM.jpg
0
 
LVL 6

Accepted Solution

by:
morpheios earned 1500 total points
ID: 37060911
May be MemorySize keyword needed instead MemoryMB?
0
 
LVL 14

Author Comment

by:RickEpnet
ID: 37060956
Ok this works. You lead me in the right direction kind of.

This was the issue
$myObj.Memory

it should have been this.
$myObj.MemoryMB


ForEach ($vm in $vms){
           if ($vm.PowerState -eq "PoweredOn") {
            $myObj = "" | select VMName, Powerstate, IPAddress, MemoryMB
            $myObj.VMName = $VM.Name
            $myObj.Powerstate = $VM.PowerState
	    $myObj.MemoryMB = $VM.MemoryMB
            $myObj.IPAddress = (Get-VMGuest -VM $VM).IPAddress[0]       
            $myCol += $myObj

Open in new window

0
 
LVL 14

Author Closing Comment

by:RickEpnet
ID: 37060958
Lead me in the right direction
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Advanced tutorial on how to run the esxtop command to capture a batch file in csv format in order to export the file and use it for performance analysis. He demonstrates how to download the file using a vSphere web client (or vSphere client) and exp…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

872 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