 |
Add-VMRdmSize |
-
-
-
-
-
-
-
-
- $VCServerName = "MYVCSERVER"
- $CustomFieldName = "RDM Size (GB)"
- $ManagedObjectType = "VirtualMachine"
-
-
- $VC = Connect-VIServer $VCServerName
- $SI = Get-View ServiceInstance
- $CFM = Get-View $SI.Content.CustomFieldsManager
-
- $myCustomField = $CFM.Field | Where {$_.Name -eq $CustomFieldName}
- If (!$myCustomField)
- {
-
- $FieldCopy = $CFM.Field[0]
- $CFM.AddCustomFieldDef($CustomFieldName,$ManagedObjectType,$FieldCopy.FieldDefPrivileges,$FieldCopy.FieldInstancePrivileges)
- }
-
-
- $VMs = Get-VM
- ForEach ($VM in $VMs)
- {
- $RDMSize = [math]::Round((($VM | Get-HardDisk | Where {$_.DiskType -ne "flat"} | Measure-Object CapacityKB -Sum).Sum * 1KB / 1GB),0)
- $VMView = $VM | Get-View
-
- If ($RDMSize -ne ($VMView.CustomValue | ?{$_.Key -eq $myCustomField.Key}).Value)
- {
-
- $VMView.setCustomValue($CustomFieldName,$RDMSize )
- }
- }
- Disconnect-VIServer -Confirm:$False