Sureshadmin
Contributor
Contributor

Need powershell scripts to collect vm disk info

Jump to solution

Hi,

I require two scripts to collect vm disk info,

1. Script to collect vm Disk mode info

Expected Output:

VM Name | ESX name | Cluster Name | vmdk name | Device Label | disksizeInGB | diskmode

Disk mode --> Just need the info like persistent or independent_persistent

2. Script to collect RDM info from Vm's

Expected output:

VM Name | ESX name | Cluster Name | DeviceName | FileName | Compatiblity Mode | Size

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

The first script

Get-VM | %{
	$vm = $_
	$vm | Get-HardDisk | %{
		$_ | select @{N="VM";E={$vm.Name}},
			@{N="ESX";E={$vm.Host}},
			@{N="Cluster";E={(Get-VMHost $vm.Host | Get-Cluster).Name}},
			@{N="VMDK";E={$_.Filename}},
			@{N="Device Label";E={$_.Name}},
			@{N="disksizeInGB";E={"{0:N1}" -f ($_.CapacityKB/1MB)}},
			@{N="Diskmode";E={$_.Persistence}}
	}
} | ft -AutoSize -Force

____________

Blog: LucD notes

Twitter: lucd22


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

View solution in original post

0 Kudos
7 Replies
LucD
Leadership
Leadership

The first script

Get-VM | %{
	$vm = $_
	$vm | Get-HardDisk | %{
		$_ | select @{N="VM";E={$vm.Name}},
			@{N="ESX";E={$vm.Host}},
			@{N="Cluster";E={(Get-VMHost $vm.Host | Get-Cluster).Name}},
			@{N="VMDK";E={$_.Filename}},
			@{N="Device Label";E={$_.Name}},
			@{N="disksizeInGB";E={"{0:N1}" -f ($_.CapacityKB/1MB)}},
			@{N="Diskmode";E={$_.Persistence}}
	}
} | ft -AutoSize -Force

____________

Blog: LucD notes

Twitter: lucd22


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

View solution in original post

0 Kudos
LucD
Leadership
Leadership

The 2nd script.

Get-VM | %{
	$vm = $_
	$vm | Get-HardDisk | where {"RawPhysical","RawVirtual" -contains $_.DiskType} | %{
		$_ | select @{N="VM";E={$vm.Name}},
			@{N="ESX";E={$vm.Host}},
			@{N="Cluster";E={(Get-VMHost $vm.Host | Get-Cluster).Name}},
			@{N="DeviceName";E={$_.DeviceName}},
			@{N="CanonicalName";E={$_.ScsiCanonicalName}},
			@{N="Filename";E={$_.Filename}},
			@{N="Compatibility Mode";E={$_.DiskType}},
			@{N="disksizeInGB";E={"{0:N1}" -f ($_.CapacityKB/1MB)}}
	}
} | ft -AutoSize -Force

Since I wasn't sure if you wanted the Device or the Canonical name I put both in.

You can remove the line of the one you don't want.

____________

Blog: LucD notes

Twitter: lucd22


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

Sureshadmin
Contributor
Contributor

Just awesome. First script works very good. Will be running second script soon.

Thanks a lot Luc.

0 Kudos
Sureshadmin
Contributor
Contributor

Luc,

Need a small change in 1st script. I need to run this script on some specific cluster's alone. Can you please alter this script so that it prompts for the cluster name and then it runs on the VM's on that particular cluster alone.

0 Kudos
LucD
Leadership
Leadership

Here you go

$cluster = Read-Host -Prompt "Enter the cluster name (<Enter> will report on all clusters)"

Get-Cluster $cluster | Get-VM | %{
	$vm = $_
	$vm | Get-HardDisk | %{
		$_ | select @{N="VM";E={$vm.Name}},
			@{N="ESX";E={$vm.Host}},
			@{N="Cluster";E={(Get-VMHost $vm.Host | Get-Cluster).Name}},
			@{N="VMDK";E={$_.Filename}},
			@{N="Device Label";E={$_.Name}},
			@{N="disksizeInGB";E={"{0:N1}" -f ($_.CapacityKB/1MB)}},
			@{N="Diskmode";E={$_.Persistence}}
	}
} | ft -AutoSize -Force

____________

Blog: LucD notes

Twitter: lucd22


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

Sureshadmin
Contributor
Contributor

Works perfect. Thank you so much.

0 Kudos
erichoge
Contributor
Contributor

Hello

Maybe it is to much what I want, but It would be great if you do this for me.

Is it possible to merge your script with the script of "ibeerens" http://communities.vmware.com/docs/DOC-7430

After "Virtual Machine information"

I tried it by myself, but I have no idea to get it in colums like all the other informations.

If it to much than maybe you can tell how get the information in a txt-file?

This would really make my day!!

Thanks in advance!

Erich

0 Kudos