Script to capture the VM information and putting that in excel.

In this script I am going to collect the basic information about the VM in environment and putting that information into excel.

#Created By Vikrant Aggarwal
$XL = New-Object -comobject Excel.Application
$TimeStamp = date
$XL.visible = $True
$WrkbkB = $XL.Workbooks.Add()
$WrkShtC = $WrkbkB.Worksheets.Item(1)
$WrkShtC.Cells.Item(1,1) = “Virtual Machine Name”
$WrkShtC.Cells.Item(1,2) = “Status”
$WrkShtC.Cells.Item(1,3) = “ProvisionedSpace”
$WrkShtC.Cells.Item(1,4) = “UsedSpace”
$WrkShtC.Cells.Item(1,5) = “NumCPU”
$WrkShtC.Cells.Item(1,6) = “MemoryGB”
$WrkShtC.Cells.Item(1,7) = “SpaceUsed%”
$WorkBook = $WrkShtC.UsedRange
$WorkBook.Font.Bold = $True
$SecRow=2
$Items = Get-VM | Select-Object -property “Name”,”PowerState”,”ProvisionedSpaceGB”,”UsedspaceGB”,”NumCPU”,”MemoryGB”
foreach ($item in $Items)
{
$WrkShtC.Cells.Item($SecRow,1)=$item.Name
$WrkShtC.Cells.Item($SecRow,2)=$item.PowerState
$WrkShtC.Cells.Item($SecRow,3)=$item.ProvisionedSpaceGB
$WrkShtC.Cells.Item($SecRow,4)=$item.UsedspaceGB
$WrkShtC.Cells.Item($SecRow,5)=$item.NumCPU
$WrkShtC.Cells.Item($SecRow,6)=$item.MemoryGB
Percentageusage $item.UsedspaceGB $item.ProvisionedSpaceGB
$SecRow++
}
function Global:Percentageusage($c,$d)
{
$WrkShtC.Cells.Item($SecRow,7)=(($c / $d) * 100)
}

$WrkShtC.EntireColumn.AutoFit()
clear

 

Below is the output which we are getting after running this script.

Capture 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s