VMware Cloud Community
raghavendrats
Contributor
Contributor
Jump to solution

Script for VMs report

Hello guys,

I am searching for a Script which can export all the VMs details in the following info.

VM Name - IP Adress - Host - OS -Current State - Memory - No of Disks - Provisioned space - Used space - Owner - Project - Completion date - description

I can export the report with all these columns except No of Disks through vcenter Server. But I need No of HDD info also. And this eport is not showing the OS and IP info for the VMs which are in Powerd odd state.

I tried through VMware Powerpacks. No use. I am unable to include the custom attributes (Owner,Project,Completion date) into the same grid.

Please attche any scripts which does this.

Thanks.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Correct, my mistake.

It was missing the counter for the guests that have 1 snapshot.

This should work better

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
15 Replies
LucD
Leadership
Leadership
Jump to solution

Some information, like the IP address, will only be available if you have the VMware Tools installed and if the guest is powered on.

$report = @()

Get-VM | %{
	$vmGuest = $_ | Get-VMGuest
	$row = "" | Select VMName, IPAddress, Host, OS,  State, Memory, NoOfDisks, ProvisionedSpaceKB, UsedspaceKb, Owner, Project, CompletionDate, Description
	$row.VMname = $_.Name
	$row.IPAddress = $vmGuest.IPAddress[0]
	$row.Host = $_.Host.Name
	$row.OS = $_.Guest.OSFullName
	$row.State = $_.PowerState
	$row.Memory = $_.MemoryMB
	$row.NoOfDisks = $_.HardDisks.Count
	$row.ProvisionedSpaceKB = ($_.HardDisks | %{$_.CapacityKB} | Measure-Object -Sum).Sum
	$row.UsedspaceKb = (Get-View  -Id $_.Id | %{$_.LayoutEx.File | where {$_.Type -eq "diskExtent"}} | %{$_.Size} | Measure-Object -Sum).Sum/1KB
	$row.Owner = $_.CustomFields
	$row.Project = $_.CustomFields
	$row.CompletionDate = $_.CustomFields
	$row.Description = $_.Notes
	$report += $row
}
$report

I attached the script in a file since the forum SW doesn't like square brackets.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
raghavendrats
Contributor
Contributor
Jump to solution

Hello Sir,

Any idea why I am getting the below error when I try to run this script. I get connected to the Server first and set the policy to un restricted & remote seigned in power CLI.

File C:\Documents and Settings\rtsathyanara\Desktop\VM Scripts\VM-report-2.ps1

cannot be loaded. The file C:\Documents and Settings\rtsathyanara\Desktop\VM Sc

ripts\VM-report-2.ps1 is not digitally signed. The script will not execute on t

he system. Please see "get-help about_signing" for more details..

At line:1 char:18

+ .\VM-report-2.ps1 <<<<

+ CategoryInfo : NotSpecified: (Smiley Happy [], PSSecurityException

+ FullyQualifiedErrorId : RuntimeException

Thanks.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That's because you downloaded the file most probably with IE.

The security mechanism adds a hidden data stream to the .ps1 file you downloaded and security doesn't allow you to execute scripts downloaded from the Inetrnet.

The easiest workaround is to open the .ps1 file you downloaded in an editor and then copy (Ctrl-a Ctrl-c) the content to a new notepad document (ctrl-v). Which you then save as a .ps1 file.

That way you get rid of the hidden data stream.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
raghavendrats
Contributor
Contributor
Jump to solution

Thank U for the quick reply. Script is running fine now. But it is not extracting datas from the Description column (Notes). It is blank in the report. and can we have disk details in GB instead of KB. I tried to modify the script ..dint work. Smiley Sad

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try the attached script

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
raghavendrats
Contributor
Contributor
Jump to solution

Thank you. At last I got a Superb Script:)

0 Kudos
raghavendrats
Contributor
Contributor
Jump to solution

Anybody help me to add one more line into this VM report script which shows No os Snapshots created on each VM.

Thanks

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Here you go.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
raghavendrats
Contributor
Contributor
Jump to solution

Thanks.. But unfortunately it is not showing the excact report. It missed snapshots count on many of my VMs in the cluster. I am running this on Vcenter server.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Correct, my mistake.

It was missing the counter for the guests that have 1 snapshot.

This should work better

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
raghavendrats
Contributor
Contributor
Jump to solution

Anybody has any idea how to include the LUN / Datastore Name in this VMs report where the particular VM is stored? I want this column to be added in this script.

Thanks.

0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

I added the datastore where the VM is stored to Luc's script.

Message was edited by: RvdNieuwendijk

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
raghavendrats
Contributor
Contributor
Jump to solution

Thank U my friend. this script is running fine. but it is not showing the Datastores for the VMs which has more than 1 Disk spreaded across different LUNs. Any way to include these info in the datasore column. Now it is showing blank for these VMs in the report.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try it with this version

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

raghavendrats
Contributor
Contributor
Jump to solution

This is working for me. Thanks.

0 Kudos