Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 179681

I need help with an inventory script for a large environment

$
0
0

So I've been tasked with building a PowerCLI script to dump an inventory of our VMWare virtual servers into a CSV document.  The inventory needs to include the servers Host Name, Domain, OS, UUID, IP assress VMWare Version, Power State, Used Space, Provisioned space, & Memory.  I have a script that I've been working on that provides some of the information, but stops providing the information after the IP address.  Also, it is PAINFULLY slow to complete.  Can someone assist me in fixing this script, or provide a working script that can give me the inventory I need?  Thanks!

 

 

 

$start = Get-Date

 

 

# Create table for output

# Name DC OS UUID IP Version PowerState CPU MemoryGB UsedSpaceGB ProvisionedSpaceGB

 

 

$table = New-Object system.Data.DataTable "Results"

 

 

$col1 = New-Object system.Data.DataColumn Name,([string])

$col2 = New-Object system.Data.DataColumn DC,([string])

$col3 = New-Object system.Data.DataColumn OS,([string])

$col4 = New-Object system.Data.DataColumn UUID,([string])

$col5 = New-Object system.Data.DataColumn IP,([string])

$col6 = New-Object system.Data.DataColumn Version,([string])

$col7 = New-Object system.Data.DataColumn PowerState,([string])

$col8 = New-Object system.Data.DataColumn CPU,([string])

$col9 = New-Object system.Data.DataColumn MemoryGB,([string])

$col10 = New-Object system.Data.DataColumn UsedSpaceGB,([string])

$col11 = New-Object system.Data.DataColumn ProvisionedSpaceGB,([string])

 

 

 

 

$table.columns.add($col1)

$table.columns.add($col2)

$table.columns.add($col3)

$table.columns.add($col4)

$table.columns.add($col5)

$table.columns.add($col6)

$table.columns.add($col7)

$table.columns.add($col8)

$table.columns.add($col9)

$table.columns.add($col10)

$table.columns.add($col11)

 

 

 

 

$duration = (New-TimeSpan $start (Get-Date)).TotalSeconds

"Created table after $duration secs"

 

 

# Get VMs object

$vms = Get-VM | Sort -property Name

 

 

$duration = (New-TimeSpan $start (Get-Date)).TotalSeconds

"Got object list of VM's after $duration secs"

 

 

foreach ($vm in $vms)

{

$row = $table.NewRow()

 

$row.Name = (Get-VM -Name $vm).Name

$row.DC = (Get-Datacenter -VM $vm).Name

$row.OS = (Get-VMGuest -VM $vm).OSFullName

$row.UUID = %{(Get-View $vm.Id).config.uuid}

$row.IP =  [string]::join(" ", ((Get-VMGuest -VM $vm).IPAddress)) # Need to join potential list of IP's

$row.Version = (Get-VM $VM |Select Version).Name

$row.PowerState = (Get-VM $VM | Select PowerState).Name

$row.CPU = (Get-VM $VM | Select NumCPU).Name

$row.MemoryGB = (Get-VM $VM |Select MemoryGB).Name

$row.UsedSpaceGB = (Get-VM $VM | Select UsedSpaceGB).Name

$row.ProvisionedSpaceGB = (Get-VM $VM | Select ProvisionedSpaceGB).Name

 

$table.Rows.Add($row)

"Added row for $vm"

}

 

 

$duration = (New-TimeSpan $start (Get-Date)).TotalSeconds

"Populated table after $duration secs"

 

 

$table | Format-Table

$table | Export-Csv -path c:\vmware\result.csv


Viewing all articles
Browse latest Browse all 179681

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>