VMware Cloud Community
raghavendrats
Contributor
Contributor

Script to extract VM didks report

Hi guys,

I have 2 ESX 4.0 hosts managing through vcenter Server. more than 50VMs are running on this. I am looking for a script to export all VM disks details. This report should include the 'Virtual Device Node' info of all VMs. I mean I wanted to have a list with how many VMs are running with IDE disk and how many are configured for SCSCI node. As I have very less knowledge on PS scripting please send me any scripts which extracts these info from vcenter server.

Thanks in Advance.

0 Kudos
4 Replies
LucD
Leadership
Leadership

I'm not sure in which format you want to see the info so the following just produces a simple report.

Each line contains the VM name, the Harddisk name and a flag that states if the harddisk is connected to an IDE controller or not.

$report = @()
Get-View -ViewType VirtualMachine | %{
	$vm = $_
	$vm.Config.Hardware.Device | where {$_.DeviceInfo.Label -like "Hard disk*"} | %{
		$hd = $_
		$IDE = $false
		$vm.Config.Hardware.Device | where {$_.Key -eq $hd.ControllerKey} | %{
			if($_.GetType().Name -like "*IDE*"){
				$IDE = $true
			}
			$row = "" | Select VMname, HDname, IDEflag
			$row.VMname = $vm.Name
			$row.HDname = $hd.DeviceInfo.Label
			$row.IDEflag = $IDE
			$report += $row
		}
	}
}
$report

If you change the last line in

$repor | Export-Csv "C:\VM-HD-report.csv" -NoTypeInformation -UseCulture

it will produce a CSV file.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
raghavendrats
Contributor
Contributor

Thank U very Much. This would be more than enough now. But unfortunately I am unable to run this in Power CLI. I entered my Host/vcenter IP in the first line $report = @(host name) and tried to run the script. It didnt work. could you please let me know is there any thing else that needs to be modofied. already connected to the server and trying to run this.

Error :

The term '.\report' is not recognized as the name of a cmdlet, function, script

file, or operable program. Check the spelling of the name, or if a path was in

cluded, verify that the path is correct and try again.

At line:1 char:9

+ .\report <<<< Hdd.ps1

+ CategoryInfo : ObjectNotFound: (.\report:String) [], CommandNot

FoundException

+ FullyQualifiedErrorId : CommandNotFoundException

Thanks.

0 Kudos
LucD
Leadership
Leadership

You first have to connect to the vCenter, like this

Connect-VIServer -Server mmmstv105 -Credential (Get-Credential)

The first line is just to define that the variable $report is an arry.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
raghavendrats
Contributor
Contributor

wow...It worked for me.

Really U R greate..King of Scripts :smileygrin:

0 Kudos