Pages: [1]
Print
Author Topic: how to create one vm-info report from several scripts?  (Read 1622 times)
R0Ge
Newbie
*
Posts: 7


View Profile
« on: July 08, 2009, 01:19:38 PM »

Hello,

I have combined serveral scripts to the following and it ceates 4 correct outputfiles.
But Is it possible to create 1 outputfile "VMinfo_Total.csv" with all the rows?.

Regards

R0Ge

# *************   Initialization Section    ***********************************

##################################
# Declare global and static variables
# VMware VirtualCenter server name
$vcserver="Sxxxx"
# Path to output file
$outputfile1="D:\Output_scripts\VMware\VMinfo_part1.csv"
$outputfile2="D:\Output_scripts\VMware\VMinfo_part2.csv"
$outputfile3="D:\Output_scripts\VMware\VMinfo_part3.csv"
$outputfile4="D:\Output_scripts\VMware\VMinfo_part4.csv"
$outputfile_total="D:\Output_scripts\VMware\VMinfo_Total.csv"

#################
# Add VI-toolkit
#################
Add-PSsnapin VMware.VimAutomation.Core
Initialize-VIToolkitEnvironment.ps1
connect-VIServer $vcserver

# *************   Start Process 1   *********************************************
$report1 = @()
Get-VM | % {
   $vm = $_ | Get-VMGuest
    $row = "" | Select VMname, VMTools, IPAddr1, IPAddr2, IPAddr3, OsFullName, Hostname
   $row.VMname = $_.Name
   $row.VMTools = $vm.State
   $row.Hostname = $vm.Hostname
   $row.IPAddr1 = $vm.IPAddress[0]
   $row.IPAddr2 = $vm.IPAddress[1]
   $row.IPAddr3 = $vm.IPAddress[3]
   $row.OsFullName = $vm.osfullname
   
    $report1 += $row
}
$report1 | sort -property VMname | Export-Csv $outputfile1 -NoTypeInformation


# *************   Start Process 2   *********************************************

$Report2 = @()
get-vm | % {
  $vm = Get-View $_.ID
    $row = "" | Select-Object VMname, VMState, TotalNics, TotalCPU, "TotalMemory Mb"
    $row.VMname = $vm.Name
    $row.VMState = $vm.summary.runtime.powerState
    $row.TotalNics = $vm.summary.config.numEthernetCards
    $row.TotalCPU = $vm.summary.config.numcpu
    $row.{TotalMemory Mb}= $vm.summary.config.memorysizemb
   
   $report2 += $row
}

$report2 | sort -property VMname | Export-Csv $outputfile2 -NoTypeInformation

# *************   Start Process 3  *********************************************

$report3 = @()
get-vm | % {
   $vm = $_
   $disksize = (($_ | get-harddisk | measure-object -property CapacityKB -sum).Sum) / 1Mb
   $_ | Get-Datastore | Where-Object {$_.Type -eq "VMFS"} | % {
      $row = "" | Select VMname, Aantaldisks, Datastore, "Total Disk GB"
      $row.VMname = $vm.Name
      $row.Aantaldisks = $vm.Harddisks.length
      $row.Datastore = $_.Name
      $row.{Total Disk GB} = $disksize
      
         $report3 += $row
   }
}
$report3 | sort -property VMname |Export-Csv $outputfile3 -noTypeInformation

# *************   Start Process 4  *********************************************

$ROTAP=@{ Name="ROTAP"; Expression={$_.CustomFields.Item("ROTAP")}}
$User=@{ Name="User"; Expression={$_.CustomFields.Item("User")}}
$Description=@{ Name="Description"; Expression={$_.CustomFields.Item("Description")}}
Get-VM | Select-Object -property "name", $ROTAP,$User,$Description | sort -property Name | Export-Csv $outputfile4 -noTypeInformation

# *************   End Process   ***********************************************
DisConnect-VIServer -confirm:$false
Logged
esarakaitis
Administrator
Full Member
*****
Posts: 218


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #1 on: July 09, 2009, 07:25:02 AM »

have you tried: $report1 | $report2 | $report3 | export-csv ?

you could also just as easily combine all that into one script, like this:

Code:
$VMs = get-vmhost | Get-VM
foreach ($VM in $VMs){
    $VMx = Get-View $VM.ID
$HW = $VMx.guest.net
    $guestinfo = $VMx.guest
foreach ($dev in $HW)
    {
        foreach ($ip in $dev.ipaddress)
        {
            $dev | select @{Name = "Name"; Expression = {$vm.name}},
@{Name = "IP"; Expression = {$ip}},
@{Name = "OS"; Expression = {$guestinfo.GuestFullName}},
                        @{Name = "Tools Status"; Expression = {$guestinfo.ToolsStatus}},
                        @{Name = "PowerState"; Expression = {$vmx.summary.runtime.powerState}},
                        @{Name = "TotatlNics"; Expression = {$vmx.summary.config.numEthernetCards}},
                        @{Name = "TotatlCPU"; Expression = {$vmx.summary.config.numcpu}},
                        @{Name = "Totatl MemoryMB"; Expression = {$vmx.summary.config.memorysizemb}}
        }
    }
}

that should be a good start for you to get going, let me know if this is what your looking to do
« Last Edit: July 09, 2009, 10:06:50 AM by esarakaitis » Logged
R0Ge
Newbie
*
Posts: 7


View Profile
« Reply #2 on: July 10, 2009, 05:23:52 AM »

Hi,

I solved it with the following script.
All the info in one file.

Thanks

Code:
# *************   Start Process    *********************************************
$report = @()
$ROTAP=@{ Name="ROTAP"; Expression={$_.CustomFields.Item("ROTAP")}}
$User=@{ Name="User"; Expression={$_.CustomFields.Item("User")}}
$Description=@{ Name="Description"; Expression={$_.CustomFields.Item("Description")}}

Get-VM | % {
$vmGuest = $_ | Get-VMGuest
$vm = Get-View $_.ID
$disksize = (($_ | get-harddisk | measure-object -property CapacityKB -sum).Sum) / 1Mb
$DataStore = ($_ | Get-Datastore | Select-Object -property 'Name')

$row = "" | Select VMname, VMTools, IPAddr1, IPAddr2, IPAddr3, OsFullName, Hostname,
                   VMState, TotalNics, TotalCPU, "TotalMemory Mb", Numberdisks, Datastore, "Total Disk GB", ROTAP, User, Description

$row.VMname = $_.Name
$row.VMTools = $vmGuest.State
$row.Hostname = $vmGuest.Hostname
$row.IPAddr1 = $vmGuest.IPAddress[0]
$row.IPAddr2 = $vmGuest.IPAddress[1]
$row.IPAddr3 = $vmGuest.IPAddress[3]
$row.OsFullName = $vmGuest.osfullname

$row.VMState = $vm.summary.runtime.powerState
$row.TotalNics = $vm.summary.config.numEthernetCards
$row.TotalCPU = $vm.summary.config.numcpu
$row.{TotalMemory Mb}= $vm.summary.config.memorysizemb

$row.Numberdisks = $_.Harddisks.length
$row.Datastore = $DataStore.Name
$row.{Total Disk GB} = $disksize

$row.ROTAP = $_.CustomFields.Item("ROTAP")
$row.User = $_.CustomFields.Item("User")
$row.Description = $_.CustomFields.Item("Description")

$report += $row
}
$report | sort -property VMname | Export-Csv $outputfile -NoTypeInformation

# *************   End Process   ***********************************************
Logged
esarakaitis
Administrator
Full Member
*****
Posts: 218


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #3 on: July 11, 2009, 10:29:32 AM »

excellent, what made you decide to go with the $row stuff? LucD likes to do things that way as well
Logged
R0Ge
Newbie
*
Posts: 7


View Profile
« Reply #4 on: July 11, 2009, 02:15:49 PM »

I am new to Powershell and started with a sample $row script (gues form LucD) and have als some $row info from him from the vmware forum.
thanks all.
Logged
trwagner1
Newbie
*
Posts: 2


View Profile
« Reply #5 on: October 28, 2009, 10:15:47 AM »

Hi,

I solved it with the following script.
All the info in one file.

Thanks

Code:
# *************   Start Process    *********************************************
$report = @()
$ROTAP=@{ Name="ROTAP"; Expression={$_.CustomFields.Item("ROTAP")}}
$User=@{ Name="User"; Expression={$_.CustomFields.Item("User")}}
$Description=@{ Name="Description"; Expression={$_.CustomFields.Item("Description")}}

Get-VM | % {
$vmGuest = $_ | Get-VMGuest
$vm = Get-View $_.ID
$disksize = (($_ | get-harddisk | measure-object -property CapacityKB -sum).Sum) / 1Mb
$DataStore = ($_ | Get-Datastore | Select-Object -property 'Name')

$row = "" | Select VMname, VMTools, IPAddr1, IPAddr2, IPAddr3, OsFullName, Hostname,
                   VMState, TotalNics, TotalCPU, "TotalMemory Mb", Numberdisks, Datastore, "Total Disk GB", ROTAP, User, Description

$row.VMname = $_.Name
$row.VMTools = $vmGuest.State
$row.Hostname = $vmGuest.Hostname
$row.IPAddr1 = $vmGuest.IPAddress[0]
$row.IPAddr2 = $vmGuest.IPAddress[1]
$row.IPAddr3 = $vmGuest.IPAddress[3]
$row.OsFullName = $vmGuest.osfullname

$row.VMState = $vm.summary.runtime.powerState
$row.TotalNics = $vm.summary.config.numEthernetCards
$row.TotalCPU = $vm.summary.config.numcpu
$row.{TotalMemory Mb}= $vm.summary.config.memorysizemb

$row.Numberdisks = $_.Harddisks.length
$row.Datastore = $DataStore.Name
$row.{Total Disk GB} = $disksize

$row.ROTAP = $_.CustomFields.Item("ROTAP")
$row.User = $_.CustomFields.Item("User")
$row.Description = $_.CustomFields.Item("Description")

$report += $row
}
$report | sort -property VMname | Export-Csv $outputfile -NoTypeInformation

# *************   End Process   ***********************************************

R0Ge, what are the custom fields in this section "ROTAP"?

I'm not sure I understand this script version with the custom fields added.

Thanks

Ted
Logged
R0Ge
Newbie
*
Posts: 7


View Profile
« Reply #6 on: October 28, 2009, 01:03:29 PM »

In Virtual Center you can add Custom Fields (Global / vm level) to a vm.
We have added 3 custom fields called User, Description, ROTAP at global level.

Vmname      User     Description     ROTAP(environment)
vm1             RoGe    Powershell     Test
vm2             Admin   mgmt              Production

this script read all the values defined in the 3 customfiels and output it to a csv.
Hope this helps.

R0Ge


 
Logged
trwagner1
Newbie
*
Posts: 2


View Profile
« Reply #7 on: October 28, 2009, 01:10:40 PM »

In Virtual Center you can add Custom Fields (Global / vm level) to a vm.
We have added 3 custom fields called User, Description, ROTAP at global level.

Vmname      User     Description     ROTAP(environment)
vm1             RoGe    Powershell     Test
vm2             Admin   mgmt              Production

this script read all the values defined in the 3 customfiels and output it to a csv.
Hope this helps.

R0Ge


 

Gotcha.  Nice script.  We don't (yet) use the customized annotation fields. 

Very nice script!  Quite nicely done.

Ted
Logged
esarakaitis
Administrator
Full Member
*****
Posts: 218


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #8 on: October 28, 2009, 02:17:00 PM »

very nice, great job!
Logged
Pages: [1]
Print
Jump to: